# What does precompilation do on a package that does not use SnoopCompile at all?

**URL:** <https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680>\
**Category:** General Usage\
**Tags:** question, precompilation\
**Created:** [January 28, 2023, 9:08am UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680 "2023-01-28T09:08:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Post date:** [January 28, 2023, 9:08am UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/1 "2023-01-28T09:08:56Z")

</div>

I’m dev’ing package does not use `SnoopCompile` or attempt any precompilation. I make frequent changes to the package locally, and everytime I do I suffer a decent precompilation delay (30 seconds) when `using` the package, e.g. whenever I run the formatter.

I’d previously asked about disabling precompilation on a package that I’m dev’ing: [Recommended way of disabling precompilation for a package I'm dev'ing](https://discourse.julialang.org/t/recommended-way-of-disabling-precompilation-for-a-package-im-deving/91539). The ` __precompile__ (false)` approach does work here: it brings the cost down to just the load time of the package, which is around 7 seconds. (I also tried the `SnoopCompile` `Preferences` approach mentioned [here](https://timholy.github.io/SnoopCompile.jl/stable/snoop_pc/) and excluded my package, but that didn’t seem to help, which probably makes sense given that my package does not use SnoopCompile.)

But here I just want to ask: what is this precompilation even doing, if I have no snoop compile calls? The only thing I can think of is that the dependencies are being precompiled, but that doesn’t make too much sense given that the precompilation time I’m suffering is when I edit my package, and only my package (which no other package depends on).

---

<div class="post-metadata">

**Author:** ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)\
**Post date:** [January 28, 2023, 9:12am UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/2 "2023-01-28T09:12:30Z")

</div>

Have you considered using [Revise](https://timholy.github.io/Revise.jl/stable/) ?

This is the typical use case when developing to avoid restarting julia and hit precompilation whenever source file content change.

---

<div class="post-metadata">

**Author:** ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Post date:** [January 28, 2023, 9:14am UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/3 "2023-01-28T09:14:59Z")

</div>

Right now I’m running into the load time issue when I’m trying to get a formatting script on my package to auto-run. Perhaps there are ways to fix that too, would love to hear about them, but this question is also just asked in curiousity about what actually contributes to the increased time when the package does not attempt to do precompilation.

---

<div class="post-metadata">

**Author:** ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)\
**Post date:** [January 28, 2023, 9:29am UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/4 "2023-01-28T09:29:11Z")

</div>

> [@tictaccat](#):
>
> I also tried the `SnoopCompile` `Preferences` approach mentioned [here](https://timholy.github.io/SnoopCompile.jl/stable/snoop_pc/) and excluded my package, but that didn’t seem to help, which probably makes sense given that my package does not use SnoopCompile.

Exactly.

> The only thing I can think of is that the dependencies are being precompiled

Your package dependencies won’t be precompiled if they didn’t change (or if [compile-time Preferences](https://docs.julialang.org/en/v1/manual/code-loading/#Package/Environment-Preferences) weren’t modified).

---

<div class="post-metadata">

**Author:** ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Post date:** [January 28, 2023, 9:30am UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/5 "2023-01-28T09:30:32Z")

</div>

Right, agreed. So I’m still not sure what it means to be “precompiling” a package that does not use SnoopCompile, and why this takes a substantial amount of time.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [January 28, 2023, 11:37am UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/6 "2023-01-28T11:37:31Z")

</div>

All packages have their methods, types, global variables, etc. stored in a cache file. The source code for your package doesn’t get parsed when you say `using MyPkg`, instead we load the snapshot of the module stored in the cache file.

But you don’t have to be explicitly using Snoop **Pre** compile for these cache files to contain more than just methods, types, and global variables: if you run anything from top level, you’re also performing type inference and compilation, and depending on your Julia version those may also get saved to the cache file. SnoopPrecompile is just more thorough about “marking” things that should be stored in the cache.

---

<div class="post-metadata">

**Author:** ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Post date:** [January 28, 2023, 11:45am UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/7 "2023-01-28T11:45:23Z")

</div>

That makes sense. My package does run code from the top level, which contributes to a load time of around 7 seconds. So precompilation of this code bumps it to 30 seconds, which makes sense.

Given that the SnoopPrecompile + preferences approach didn’t work, is there any planned way to disable this precompilation for specific packages without editing the source code of the package? (I also wonder if it could be any smarter about this; the whole precompilation process gets triggered with just a mere edit of a docstring)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [January 28, 2023, 5:01pm UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/8 "2023-01-28T17:01:27Z")

</div>

> [@tictaccat](#):
>
> My package does run code from the top level, which contributes to a load time of around 7 seconds.

Just to make sure we’re on the same page: running code at top level in your package code contributes to _precompilation time_, not _load time_. Because you’re just loading a snapshot. Here’s a very simple demo:

```julia
module Pkg1

foo(x) = 2x

sleep(30)

end

```

with results

```julia
julia> @time using Pkg1
[Info: Precompiling Pkg1 [da3b0148-1b4b-4ae0-b07b-5f650a6bd540]
 30.673267 seconds (28.77 k allocations: 1.911 MiB, 0.09% compilation time)

julia>
tim@diva:/tmp/pkgsA/dev$ JULIA_DEPOT_PATH=/tmp/pkgsA julia -q
julia> @time using Pkg1
  0.007512 seconds (13.29 k allocations: 929.343 KiB)

```

So the precompilation time was 30s because we ran some code at top level, and that code required 30s to run. But loading the package was practically instantaneous, because that `sleep` doesn’t run when you load the package.

It’s quite easy to run code at top level and not realize it: heck, `const x = [1, 2]` runs `Base.vect` to build the vector from the literals.

For more complicated packages, there is some time simply to cache methods etc. But the most likely culprit probably remains the stuff that runs at toplevel. On 1.9 and higher, you can use [PkgCacheInspector](https://github.com/timholy/PkgCacheInspector.jl) and [MethodAnalysis](https://github.com/timholy/MethodAnalysis.jl) to learn some of the things that got compiled while you were building the package. (Julia will discard code that it can’t prove will be useful for the package itself, and that’s what the “marking” in SnoopPrecompile is about. So even PkgCacheInspector will not necessarily be comprehensive.)

---

<div class="post-metadata">

**Author:** ![tictaccat](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tictaccat](https://discourse.julialang.org/u/tictaccat)\
**Post date:** [July 15, 2023, 8:03pm UTC](https://discourse.julialang.org/t/what-does-precompilation-do-on-a-package-that-does-not-use-snoopcompile-at-all/93680/9 "2023-07-15T20:03:49Z")

</div>

Related! [Top level code in JuliaLang doesn't do what you think it does](https://www.oxinabox.net/2023/06/16/top-level-code-in-julia.html)
