Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect type unstable functions in Julia

Tags:

julia

Setup: Let's say I have a reasonably detailed piece of software (in Julia), involving the interaction of several modules. I feel like it is running slower than it should. Typically the first culprit to check for is type unstable functions, i.e. functions where the compiler is unable to determine ahead of time what the output type will be.

Question: How can I detect these type unstable functions?

What I currently do: I use the profiling tools, e.g. the ProfileView.jl package of @tholy, to detect bottlenecks, under the assumption that type unstable functions will show up here (due to their excessive run-time). But what would be really nice is some sort of debugging tool that, after a routine is run, will spit out a list of functions where the compiler was unable to determine the output type ahead of time. Is this possible?

like image 928
Colin T Bowers Avatar asked Jan 22 '15 02:01

Colin T Bowers


2 Answers

You could try TypeCheck.jl on bits the profiler say are slow.

Julia 0.4 has @code_warntype as well.

like image 125
IainDunning Avatar answered Nov 13 '22 05:11

IainDunning


In addition to the excellent suggestions of IainDunning, running julia with --track-allocation=user and analyzing the results with analyze_malloc from the Coverage package is a good way to quickly get a high-level overview. The principle is that type-instability triggers memory allocation, so looking for lines of code that have unexpected, large allocations is a good way to find the most egregious instances of type instability.

You can find more information about track-allocation in the manual, and even more performance-analysis options described.

like image 35
tholy Avatar answered Nov 13 '22 06:11

tholy