Could anyone recommend the best tool for analyzing Julia’s compilation process? I’m facing an issue where my code runs quickly, but the compilation time is excessively slow. I’ve looked into generic advice regarding TypeValues, but that doesn’t seem to be the root of the problem in my case.
As I’m new to this type of issue, I’m seeking an automated tool that could assist in identifying the bottleneck. Any suggestions or guidance would be greatly appreciated.
The thread is quite old. A lot has changed since then. Of course, invalidations are still relevant but SnoopCompile.jl got major updates in between.
Just to be sure, the first step should be profiling with @profview or similar tools to see the lines of code most time is spend. Even if runtime is fast, it might give an indication.
Once you go into details, then SnoopCompile.jl, JET.jl and Cthulhu.jl are useful. See also Optimizing your code .
to ask “which of my MethodInstances takes longest to infer?”, use@snoopi_deep
to ask “which of my CodeInstances takes the longest for LLVM to optimize?”, then use julia --trace-compile or @snoopl
to ask, “which part of inference or codegen is causing the bottleneck?”, start a fresh session and use @profile call_my_function(args...) for the first time. You’ll be mostly profiling the compiler, assuming your function runs quickly once compiled.
Profiling the first run was really helpful. My actual problem was with hcat(staticvectors...). In this scenario, for each different number of static vectors, hcat precompiles a different method. I replaced it with stack(staticvectors), and my problem was resolved with no loss of runtime performance.