# What's actually inside precompiled Julia files?

**URL:** https://discourse.julialang.org/t/whats-actually-inside-precompiled-julia-files/28234
**Category:** General Usage
**Created:** [August 31, 2019, 12:06pm UTC](https://discourse.julialang.org/t/whats-actually-inside-precompiled-julia-files/28234 "2019-08-31T12:06:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)
#### Post date: [August 31, 2019, 12:06pm UTC](https://discourse.julialang.org/t/whats-actually-inside-precompiled-julia-files/28234/1 "2019-08-31T12:06:35Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [August 31, 2019, 2:12pm UTC](https://discourse.julialang.org/t/whats-actually-inside-precompiled-julia-files/28234/2 "2019-08-31T14:12:52Z")

</div>

> [@ninjaaron](#):
>
> 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)

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`](https://docs.julialang.org/en/latest/base/base/#Base.precompile) is called. The [SnoopCompile package](https://github.com/timholy/SnoopCompile.jl) can automatically generate `precompile` statements for functions that are called during a program execution.

> [@ninjaaron](#):
>
> 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?

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

> [@ninjaaron](#):
>
> Also, is it possible write Julia in a way that optimizes for precompilation and thereby reduces runtime compilation overhead?

Use SnoopCompile.

---

<div class="post-metadata">

### Author: ![ninjaaron](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ninjaaron/32/6392_2.png) [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)
#### Post date: [August 31, 2019, 2:19pm UTC](https://discourse.julialang.org/t/whats-actually-inside-precompiled-julia-files/28234/3 "2019-08-31T14:19:13Z")

</div>

Thanks, @stevengj!
