# How to avoid code getting precompiled because it gets executed while the package is being defined?

**URL:** <https://discourse.julialang.org/t/how-to-avoid-code-getting-precompiled-because-it-gets-executed-while-the-package-is-being-defined/126890>\
**Category:** General Usage\
**Tags:** question, package, precompilation, methods, precompile\
**Created:** [March 12, 2025, 10:38pm UTC](https://discourse.julialang.org/t/how-to-avoid-code-getting-precompiled-because-it-gets-executed-while-the-package-is-being-defined/126890 "2025-03-12T22:38:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [March 12, 2025, 10:38pm UTC](https://discourse.julialang.org/t/how-to-avoid-code-getting-precompiled-because-it-gets-executed-while-the-package-is-being-defined/126890/1 "2025-03-12T22:38:36Z")

</div>

Often times I have some code in a package that executes only during precompilation, not at run time. AFAIK Julia saves the `MethodInstance`s of all such compiled `Method`s into the precompilation files, for some reason. How to turn that off?

An example is a line such as this:

```julia
const SomeType = Union{typeof.((func1, func2, func3))} # the broadcast gets compiled unnecessarily

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [March 13, 2025, 2:12am UTC](https://discourse.julialang.org/t/how-to-avoid-code-getting-precompiled-because-it-gets-executed-while-the-package-is-being-defined/126890/2 "2025-03-13T02:12:17Z")

</div>

`PrecompileTools.@setup_workload` is designed to skip precompilation caching (mostly, it documents a few vague caveats), but that’s for code preparing the precompile workload. I don’t know if it can be repurposed for preparing global `const`s.
