# Log whenever a method is compiled

**URL:** <https://discourse.julialang.org/t/log-whenever-a-method-is-compiled/103823>\
**Category:** General Usage\
**Created:** [September 13, 2023, 6:00pm UTC](https://discourse.julialang.org/t/log-whenever-a-method-is-compiled/103823 "2023-09-13T18:00:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![taotree](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taotree/32/31982_2.png) [@taotree](https://discourse.julialang.org/u/taotree)\
**Post date:** [September 13, 2023, 6:00pm UTC](https://discourse.julialang.org/t/log-whenever-a-method-is-compiled/103823/1 "2023-09-13T18:00:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)\
**Post date:** [September 13, 2023, 6:10pm UTC](https://discourse.julialang.org/t/log-whenever-a-method-is-compiled/103823/2 "2023-09-13T18:10:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![taotree](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taotree/32/31982_2.png) [@taotree](https://discourse.julialang.org/u/taotree)\
**Post date:** [September 13, 2023, 6:56pm UTC](https://discourse.julialang.org/t/log-whenever-a-method-is-compiled/103823/3 "2023-09-13T18:56:43Z")

</div>

Thanks! SnoopCompile helped some:

```julia
using SnoopCompile
results = @snoopi_deep run_the_big_code(...)
staleinstances(results)

```

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.

---

<div class="post-metadata">

**Author:** ![taotree](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taotree/32/31982_2.png) [@taotree](https://discourse.julialang.org/u/taotree)\
**Post date:** [September 13, 2023, 7:25pm UTC](https://discourse.julialang.org/t/log-whenever-a-method-is-compiled/103823/4 "2023-09-13T19:25:59Z")

</div>

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

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

```

showed the problems.
