# Tools to Analyze Long Julia Compilation Times

**URL:** <https://discourse.julialang.org/t/tools-to-analyze-long-julia-compilation-times/109510>\
**Category:** New to Julia\
**Tags:** question, compilation\
**Created:** [January 31, 2024, 12:54pm UTC](https://discourse.julialang.org/t/tools-to-analyze-long-julia-compilation-times/109510 "2024-01-31T12:54:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nimrais](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nimrais/32/47188_2.png) [@Nimrais](https://discourse.julialang.org/u/Nimrais)\
**Post date:** [January 31, 2024, 12:54pm UTC](https://discourse.julialang.org/t/tools-to-analyze-long-julia-compilation-times/109510/1 "2024-01-31T12:54:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [January 31, 2024, 2:16pm UTC](https://discourse.julialang.org/t/tools-to-analyze-long-julia-compilation-times/109510/2 "2024-01-31T14:16:58Z")

</div>

Check out [this thread!](https://discourse.julialang.org/t/profiling-module-precompilation/33438/5)

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [January 31, 2024, 2:51pm UTC](https://discourse.julialang.org/t/tools-to-analyze-long-julia-compilation-times/109510/3 "2024-01-31T14:51:24Z")

</div>

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](https://modernjuliaworkflows.github.io/pages/optimizing/optimizing/) .

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [January 31, 2024, 7:31pm UTC](https://discourse.julialang.org/t/tools-to-analyze-long-julia-compilation-times/109510/4 "2024-01-31T19:31:10Z")

</div>

It depends on the question you want to ask.

- 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.

---

<div class="post-metadata">

**Author:** ![Nimrais](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nimrais/32/47188_2.png) [@Nimrais](https://discourse.julialang.org/u/Nimrais)\
**Post date:** [February 1, 2024, 1:17pm UTC](https://discourse.julialang.org/t/tools-to-analyze-long-julia-compilation-times/109510/5 "2024-02-01T13:17:25Z")

</div>

Thanks!

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.
