What is included in the output of `--trace-compile`?

--trace-compile-timing works the same way as --trace-compile: you get one line of output for each time compilation was triggered, and no output for compilation that happens as a direct result of that. The time includes the time for all the type inference and compilation that was necessary before the method was ready to call.

You can probably predict what will happen here:

$ julia --trace-compile=stderr --trace-compile-timing -e 'foo(x) = x+1; bar(x) = foo(x)*2; foo(1); bar(2)'
#=    1.6 ms =# precompile(Tuple{typeof(Main.foo), Int64})
#=    1.2 ms =# precompile(Tuple{typeof(Main.bar), Int64})

In this case, foo gets inlined into bar, so the standalone version of foo doesn’t get compiled until it is called afterwards.

$ julia --trace-compile=stderr --trace-compile-timing -e 'foo(x) = x+1; bar(x) = foo(x)*2; bar(2); foo(1)'
#=    1.7 ms =# precompile(Tuple{typeof(Main.bar), Int64})
#=    1.4 ms =# precompile(Tuple{typeof(Main.foo), Int64})

If I mark foo as @noinline, compiling bar causes the standalone version of bar to get compiled, so when I call it later it doesn’t produce a line of output.

$ julia --trace-compile=stderr --trace-compile-timing -e '@noinline foo(x) = x+1; bar(x) = foo(x)*2; bar(2); foo(1)'
#=    2.5 ms =# precompile(Tuple{typeof(Main.bar), Int64})

If you want to see the time spent in a tree, SnoopCompile.jl is what you want. If you want a really detailed look at exactly what Julia was doing during compilation, you can build Julia with profiling support.

2 Likes