# PackageCompiler: does \`precompile\` store machine code?

**URL:** <https://discourse.julialang.org/t/packagecompiler-does-precompile-store-machine-code/88480>\
**Category:** General Usage\
**Tags:** package-compiler\
**Created:** [October 9, 2022, 2:42pm UTC](https://discourse.julialang.org/t/packagecompiler-does-precompile-store-machine-code/88480 "2022-10-09T14:42:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tfiers/32/32427_2.png) [@tfiers](https://discourse.julialang.org/u/tfiers)\
**Post date:** [October 9, 2022, 2:42pm UTC](https://discourse.julialang.org/t/packagecompiler-does-precompile-store-machine-code/88480/1 "2022-10-09T14:42:18Z")

</div>

You can pass Julia code to [`create_sysimage`](https://julialang.github.io/PackageCompiler.jl/dev/refs.html) using:

- `precompile_execution_file` / `precompile_statements_file`; and
- `script`

Do I have it correct that the first option only stores type inference in the sysimage, and not [generated machine code](https://timholy.github.io/SnoopCompile.jl/stable/#Background), while using `script` stores both?

If so, what’s the use of `precompile_execution_file`; why would anyone not always use `script` instead.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [October 9, 2022, 4:37pm UTC](https://discourse.julialang.org/t/packagecompiler-does-precompile-store-machine-code/88480/2 "2022-10-09T16:37:25Z")

</div>

All variants compile machine code instructions.

The `precompile_*` are used to create a file that is executed to output the object file.  
If you provide a `precompile_executation_file` that will actually be converted into precompile statements either way. The precompile statements are then wrapped with some Julia code.  
(See [here](https://github.com/JuliaLang/PackageCompiler.jl/blob/c0e68553c7a74bd580ba7238816ab7c4b7ce4b9c/src/PackageCompiler.jl#L266). )

The script is just some plain Julia code you can append to the executed Julia code. This way you essentially skip all the smart things PackageCompiler does. (See [here](https://github.com/JuliaLang/PackageCompiler.jl/blob/c0e68553c7a74bd580ba7238816ab7c4b7ce4b9c/src/PackageCompiler.jl#L338).)

I am not sure what the script is for, but from the source code, it seems like one shouldn’t use it if there is no reason for it. Like it could for example add more things to the sysimage than wanted.

---

<div class="post-metadata">

**Author:** ![tfiers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tfiers/32/32427_2.png) [@tfiers](https://discourse.julialang.org/u/tfiers)\
**Post date:** [October 9, 2022, 4:49pm UTC](https://discourse.julialang.org/t/packagecompiler-does-precompile-store-machine-code/88480/3 "2022-10-09T16:49:09Z")

</div>

> [@SteffenPL](#):
>
> All variants compile machine code instructions.

Interesting, thank you.  
So there is a difference in what [`precompile`](https://docs.julialang.org/en/v1/base/base/#Base.precompile) does in a normal Julia session [1] and in one with `--output-o`

[1] Namely only type inference, not generate machine code, as explained at  
[https://timholy.github.io/SnoopCompile.jl/stable/#Background](https://timholy.github.io/SnoopCompile.jl/stable/#Background) (Unless I misunderstand that text).

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [October 9, 2022, 9:40pm UTC](https://discourse.julialang.org/t/packagecompiler-does-precompile-store-machine-code/88480/4 "2022-10-09T21:40:05Z")

</div>

Yes, I think the link you shared explains the difference well. 👍
