Log whenever a method is compiled

When I run certain code with @time, it’s showing that most of the time is in compilation. It happens every time even though the code hasn’t changed. Usually, it compiles code the first time, and subsequent runs use that. However, that’s not happening in this case. There’s a lot of code involved, so I’m trying to track down where it’s happening.

Is there a way to tell the compiler to output some info every time it recompiles a method? Any other tools to troubleshoot this type of situation?

It would be really nice if there was a way to do this without having to leave an existing Julia repl session.

The SnoopCompile package may come in handy if you want to debug or understand this.

1 Like

Thanks! SnoopCompile helped some:

using SnoopCompile
results = @snoopi_deep run_the_big_code(...)

And that output a list of methods that were causing the problem. I tweaked the code in them and the recompilation went away. One place I removed setting a global, and another I added a @nospecialize around a StaticArray argument.

However, It’s still happening even after @snoopi_deep is returning nothing. And @snoopr returned nothing (Any[]) from the beginning.

Ah, I wasn’t looking at the right results. I needed to use print_tree, not staleinstances. Running:

using SnoopCompile, AbstractTrees
results = @snoopi_deep run_the_big_code(...)

showed the problems.