Precompilation of Module

I am working in VSC (Visual Studio Code) and added ModelingToolkit.jl to the packages. All went well, and then I typed using ModelingToolkit, and all was good. Then I went to a different window, and started up Julia on the terminal command line (on Mac Ventura) and executed Julia with --check_bounds=yes. What was strange is that ModelingToolkit got precompiled. Why would that happen? Thanks.

check_bounds=yes may have forced recompilation. Otherwise, anything that touches the source files may have also influenced the need for precompilation. Also, a different environment, possibly involving a different package version may be responsible.

One of these is the culprit more than likely. It is a pain and unexpected. It would be nice if the user could control this with compilation options like in C++: -O0, -O1, -O2. I have the impression that Julia is always compiled full blast. Cheers.

Two options.

There’s a command line option:

    julia [switches] -- [programfile] [args...]

Switches (a '*' marks the default value, if applicable):
...
 -O, --optimize={0,1,2*,3}  Set the optimization level (level 3 if `-O` is used without a level)

There is also a per-module option:

help?> Base.Experimental.@optlevel
  Experimental.@optlevel n::Int

  Set the optimization level (equivalent to the -O command line argument) for code in the current module. Submodules inherit the setting of their parent module.

  Supported values are 0, 1, 2, and 3.

  The effective optimization level is the minimum of that specified on the command line and in per-module settings. If a --min-optlevel value is set on the command line,
  that is enforced as a lower bound.

The above deals with native code generation. Note that “precompilation” does not refer to any of the above. It refers to parsing and type inference only, not native code generation.

Thanks! I will learn more about these options!

Just to be clear, Julia uses the LLVM compiler framework. The clang compiler also uses this framework. If you would like the gritty details of what each optimization level does in terms of LLVM options here is the source code:

1 Like