How to disable precompilation?

Suppose I want to load package P. If I do using P, the package and all its dependencies get precompiled before the statement returns. Is there a way to disable precompilation, so compilation would only happen on-demand, and the package would get loaded sooner?

2 Likes

If you are in a project environment, the package should only precompile once, since it is cached, until it is updated or its dependencies are. Just be sure that the environment is active.

using Pkg
Pkg.activate(@__DIR__)

Well, that was not question. The question was, how to disable even the first precompilation.

AI says: Set the environment variable ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0 before launching Julia or at the top of your script to prevent Julia from automatically precompiling packages when you add or use them.

I did not try this myself, not sure if that works. But give it a try.

1 Like

I haven’t tried this either, but the docs suggest that this only disables precompilation after the manifest changes:

If set to 0, this will disable automatic precompilation by package actions which change the manifest. See Pkg.precompile.


To add another comment (or rather question) that doesn’t quite answer your question: Does __precompile__(false) solve the issue when added to the module P (assuming you have access to it)?

I’m looking to disable precompilation.

Yeah. I always use that environment variable and it’s not what I want here.

No. I want this for arbitrary packages, without having to modify them first.

1 Like
julia --compiled-modules=no

maybe?

From the docs:

It is sometimes helpful during module development to turn off incremental precompilation. The command line flag --compiled-modules={yes|no|existing} enables you to toggle module precompilation on and off. When Julia is started with --compiled-modules=no the serialized modules in the compile cache are ignored when loading modules and module dependencies. In some cases, you may want to load existing precompiled modules, but not create new ones. This can be done by starting Julia with --compiled-modules=existing. More fine-grained control is available with --pkgimages={yes|no|existing}, which only affects native-code storage during precompilation. Base.compilecache can still be called manually. The state of this command line flag is passed to Pkg.build to disable automatic precompilation triggering when installing, updating, and explicitly building packages.

4 Likes

But also this might be an X/Y problem. Why specifically do you want to do this?

1 Like

Doesn’t work. Precompilation of the package and all deps still happens when running using Package. Seems --compiled-modules=existing --compile=min -O0 does the trick after all. I actually tried this option before opening the thread, but somehow I think the results were different that time? Perhaps it’s necessary to also clear any preexisting relevant precompilation files.

In this case I just want run some methods queries to see what methods exist after a package and all its dependencies are loaded.

1 Like