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

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

An example is a line such as this:

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

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 consts.