How to determine the type of unstable functions in Julia

Setup: Let's say I have a fairly detailed software (in July), which involves the interaction of several modules. I feel it is running slower than necessary. Usually the first culprit of the check is unstable type functions , i.e. Functions in which the compiler cannot determine in advance what type of output will be.

Question: How can I detect these unstable type functions?

What I am doing now: I use profiling tools, for example. ProfileView.jl @tholy package to identify bottlenecks under the assumption that unstable functions will appear here (due to their excessive runtime). But what would be very nice is some kind of debugging tool that, after running the subroutine, spits out a list of functions where the compiler could not determine the type of output ahead of time. Is it possible?

+6
source share
2 answers

You can try TypeCheck.jl on bits that the profiler speaks slowly.

Julia 0.4 has @code_warntype .

+6
source

In addition to the excellent IainDunning suggestions, running julia using --track-allocation=user and analyzing the results using 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 finding lines of code with unexpected large allocations is a good way to find the most egregious instances of type instability.

Further information on track-allocation in the manual and even more performance analysis options are described .

+4
source

Source: https://habr.com/ru/post/981380/