# Where is load-time spent (with skipped precompilation)

**URL:** <https://discourse.julialang.org/t/where-is-load-time-spent-with-skipped-precompilation/89201>\
**Category:** Performance\
**Created:** [October 24, 2022, 5:41pm UTC](https://discourse.julialang.org/t/where-is-load-time-spent-with-skipped-precompilation/89201 "2022-10-24T17:41:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tfiers/32/32427_2.png) [@tfiers](https://discourse.julialang.org/u/tfiers)\
**Post date:** [October 24, 2022, 5:41pm UTC](https://discourse.julialang.org/t/where-is-load-time-spent-with-skipped-precompilation/89201/1 "2022-10-24T17:41:28Z")

</div>

In a new Julia session, I import a custom package of mine:

```julia
@time @time_imports using VoltoMapSim

```

which gives

```julia
[Info: Precompiling VoltoMapSim [f713100b-c48c-421a-b480-5fcb4c589a9e]
[Info: Skipping precompilation since __precompile__ (false). Importing VoltoMapSim [f713100b-c48c-421a-b480-5fcb4c589a9e].
   1214.4 ms Sciplotlib 58.35% compilation time
      0.5 ms Adapt
     51.3 ms StructArrays
     83.4 ms Latexify 44.93% compilation time (52% recompilation)
      1.1 ms SpikeLab
     22.1 ms FiniteDiff 39.95% compilation time (100% recompilation)
    314.1 ms NLSolversBase
      4.7 ms LsqFit
Running VoltoMapSim. __init__ … done (0.0 s)
 12.414818 seconds (17.24 M allocations: 947.780 MiB, 5.01% gc time, 65.02% compilation time: 2% of which was recompilation)

```

There is a large pause between the last import (“`4.7 ms LsqFit`”)  
and the package init (“`Running VoltoMapSim. __init__ `”).  
What is happening in those ~10 seconds?

Notes:

- I do not precompile my top-level package (_VoltoMapSim_), because I change its code more often than I restart Julia. (Every small code-change would recompile the whole thing). I use Revise.jl instead.
- Heavy packages are already in a custom sysimage.

An extra question: why is my custom downstream package _Sciplotlib_ being re-compiled (“`1214.4 ms Sciplotlib 58.35% compilation time`”), even though I haven’t changed it?  
Does this have something to do with ‘invalidations’? I do not extend any of its functions.

---

<div class="post-metadata">

**Author:** ![tfiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tfiers/32/32427_2.png) [@tfiers](https://discourse.julialang.org/u/tfiers)\
**Post date:** [October 25, 2022, 12:30am UTC](https://discourse.julialang.org/t/where-is-load-time-spent-with-skipped-precompilation/89201/2 "2022-10-25T00:30:03Z")

</div>

Answering myself: I profiled with [SnoopCompile](https://timholy.github.io/SnoopCompile.jl/stable/snoopi_deep/):

```julia
using SnoopCompile, ProfileView
tinf = @snoopi_deep (using VoltoMapSim)
ProfileView.view(flamegraph(tinf));

```

Turns out, a lot of this import time is spent in compiling expanded **macro calls** :

- `@match` (Match.jl)
- `@showprogress` (ProgressMeter.jl)
- `@with_kw` (Parameters.jl)
- `f"Python-style f-string {x:.2f}"` (PyFormattedStrings.jl)
- `@set` (Setfield.jl)

Plus:

- `ComponentVector(; myname=1, othername=2, …)` (ComponentArrays.jl)
- `PyCall.setindex!(::PyDict{…}, …)` (PyPlot.jl)
- a bunch of custom `Tuple` and `NamedTuple` constructions

I’ll see if I can get rid of some of those / maybe precompile them in an upstream less-updated package.
