What's actually inside precompiled Julia files?

I’m talking about the files like those in the various subfolders of ~/.julia/compiled.

Obviously machine code can’t really be compiled until all the all types are known–something that typically isn’t possible for entire modules outside the context of a complete program (and sometimes not until runtime)

I’m curious what portions of the Julia code actually get compiled, and also what the output is. I know the text of the program is also included in the compiled output, but there are a lot of other bytes. Is that machine code or some other intermediate representation?

Also, is it possible write Julia in a way that optimizes for precompilation and thereby reduces runtime compilation overhead?

Actually, many types are known when the module is loaded — any functions that are called during module initialization, along with any function for which precompile is called. The SnoopCompile package can automatically generate precompile statements for functions that are called during a program execution.

My understanding is that it’s currently the lowered+type-inferred code, plus the values of global variables (e.g. const foo = ...some expensive function...). When a precompiled module is loaded, only its __init__ function is called since the results of any top-level code execution (e.g. generated code via @eval statements or computation of global constants) were cached.

Since precompilation already has type-inferred code, caching machine code is “merely” a technical implementation issue, which is why we are pretty confident it will be completed in a future Julia version (now that the multithreading milestone in 1.3 has been achieved).

Use SnoopCompile.

4 Likes

Thanks, @stevengj!