# Precompilation and package compiler

**URL:** <https://discourse.julialang.org/t/precompilation-and-package-compiler/83141>\
**Category:** General Usage\
**Created:** [June 21, 2022, 7:45pm UTC](https://discourse.julialang.org/t/precompilation-and-package-compiler/83141 "2022-06-21T19:45:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [June 21, 2022, 7:45pm UTC](https://discourse.julialang.org/t/precompilation-and-package-compiler/83141/1 "2022-06-21T19:45:43Z")

</div>

Hello, we’re creating binaries using PackageCompiler.jl, and it’s working well, but… right now we have a script `create_precompile.jl` which we use to create a `build/MyPackage_precompile.jl` file full of precompile statements, which is git-tracked. The script is run occasionally, as of course the code evolves and the precompile statements is out of date.

This feels bananas to me, because:

- git-tracking a generated file is generally not recommended
- Keeping it up to date is a PITA
- I thought that `precompile(f, ...)` is equivalent to `f(...)`, except that it does not run the function. Ergo: instead of `MyPackage_precompile.jl` being full of soon-obsoleted precompilation statement, we could just run the “sample run” code in `create_precompile.jl` at package compilation time.

I haven’t looked into all of the PackageCompiler details, so maybe my assumptions are way off, but my mental model is that when it runs, it will save to the sysimage all compiled method instances in the current julia process, so it doesn’t matter whether those were created by a sample script, or by `precompile` statements.

Am I wrong?

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [June 21, 2022, 8:05pm UTC](https://discourse.julialang.org/t/precompilation-and-package-compiler/83141/2 "2022-06-21T20:05:16Z")

</div>

After some back-and-forth with colleagues and reading of the docs, it seems the answer is… [precompile\_execution\_file](https://docs.juliahub.com/PackageCompiler/MMV8C/1.2.1/refs.html#PackageCompiler.create_app)

🎉

I’m still puzzled why some packages have endless `precompile` statements, but it seems that we’re good for PackageCompiler

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 21, 2022, 8:16pm UTC](https://discourse.julialang.org/t/precompilation-and-package-compiler/83141/3 "2022-06-21T20:16:52Z")

</div>

> [@cstjean](#):
>
> I’m still puzzled why some packages have endless `precompile` statements, but it seems that we’re good for PackageCompiler

Packages are in general starting to moving over to having a representative workload run during precompilation instead of an explicit precompile file.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [June 21, 2022, 8:18pm UTC](https://discourse.julialang.org/t/precompilation-and-package-compiler/83141/4 "2022-06-21T20:18:38Z")

</div>

In addition, you could also use your `runtest.jl` script to perform the precompilation, so that you do not have code duplication between tests and precompilation. It also forces you to keep test up to date with new features, resulting in overall better testing.

---

<div class="post-metadata">

**Author:** ![ianshmean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ianshmean/32/216042_2.png) [@ianshmean](https://discourse.julialang.org/u/ianshmean)\
**Post date:** [June 21, 2022, 8:37pm UTC](https://discourse.julialang.org/t/precompilation-and-package-compiler/83141/5 "2022-06-21T20:37:06Z")

</div>

> Packages are in general starting to moving over to having a representative workload run during precompilation instead of an explicit precompile file.

@cstjean here’s a related PR with new docs that aims to cover this

> <https://github.com/JuliaLang/julia/pull/45650/files>
>
> \`ccall(:jl\_generating\_output, Cint, ()) == 1\` is used in the ecosystem widely to… guard precompilation code. It seems like it should be formally in the API.
> 
> A slack discussion with @timholy arrived at this name. \`is\_precompiling\` seemed like a good name at first, but is confused by \`precompile\` calls, which \_precompile\_ code at a time where \`jl\_generating\_output != 1\`. And \`is\_generating\_output\` seemed a bit vague.
