My code is heavy on parametric types, and rather slow to compile. I would like to know on which functions that time is being spent. Is there a tool to report on that?
Barring that, is there a way to force compilation of fun with arg_types, without executing it? Is it reasonable to approximate compilation time by timing @time @code_native(fun(args...)) (assuming that this particular specialization hasn’t been compiled yet)?
In my tests, calling precompile on all functions used in some code took longer than just running that code, so I initially thought that this wouldn’t work as a compile-time proxy. But I’m guessing that it’s because precompile takes a tuple of types, which is something the Julia compiler doesn’t handle so well. I “warmed up” precompile for those type tuples to get rid of that time. Code here
@yuyichao Can I please ask for your opinion on this? I’d like to measure per-specialization compilation time. I realize that this is a potentially ill-defined quantity, but I would like a reasonable approximation. Consider two functions that take an integer, and that may or may not have been called already.
f(x) = g(x) + 2
g(x) = sin(x) + ...
Is it reasonable to profile them this way?
precompile(g, (Int,)) # warm up the precompilation
f(x) = g(x) + 2 # redefine the functions to clear the specialization cache
g(x) = sin(x) + ...
@show @elapsed(precompile(g, (Int,))
@show @elapsed(precompile(f, (Int,)) # measure the caller after the callee
No this is not the issue. precompile currently only generate LLVM code. This is the desired behavior for sysimg compilation but may not be the desired behavior for package precompilation (in which case one should not generate llvm IR since they are not going to be used currently) or runtime (in which case it might be better to generate native code).
This will currently not include native code generation time.
Is there a way to trigger native code generation? Alternatively, can I reasonably assume that native code generation is negligible, or roughly proportional in time to the rest of the compilation pipeline?