# Shorten time to create\_app() using PackageCompiler

**URL:** <https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274>\
**Category:** General Usage\
**Created:** [February 27, 2023, 3:02pm UTC](https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274 "2023-02-27T15:02:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pablo](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Pablo](https://discourse.julialang.org/u/Pablo)\
**Post date:** [February 27, 2023, 3:02pm UTC](https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274/1 "2023-02-27T15:02:42Z")

</div>

Is there any way to reduce the time it takes to create a julia app with package compiler?

I have found the `filter_stdlibs=true` arg in the PackageCompiler docs, but I wonder if there’s anything else I can do

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [February 27, 2023, 6:45pm UTC](https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274/2 "2023-02-27T18:45:55Z")

</div>

The reason for compiling slowly (for any language) is compiling at non-low optimization level (often involving use of inlining, which is on by default in Julia, but I believe disabled by default at lower levels, also settable separately), and/or compiling too much.

I would compile with the latest available Julia version (since they are getting better over time), even 1.10/master for speed. Julia 1.9 RC is around the corner, 1.9 would also be a rather safe bet, and while only stable builds, e.g. 1.8, are recommended for production, I’m recommending newer than that for a non-final build only. If I recall there was some recent improvement for compiling the sysimage, why I’m recommending recent Julia, and explaining:

Julia (when Julia itself is compiled) takes a lot of time compiling its sysimage (basically all the standard library). And I understand since there’s only one sysimage, when you compile your app, you have the (relatively) fixed overhead of triggering compiling all of the standard library as an overhead. I believe there’s no easy solution to strip out parts of the standard library you don’t need, or which parts do not get precompiled. That’s something to look into (one reason I want a cut-down version of Julia, e.g. without LinearAlgebra not all users need). As a stop-gap solution would be to compile at a lower optimization. I don’t belief you could set it separately for your own code than for the standard library (i.e. it’s a global setting, though it IS also settable at a module level).

If you compile often (or just don’t care too much about fastest generated code for your final build) you can run with lower optimization level, e.g. `-O0`. Then for a final compile build you usually want more optimization, either the default level Julia provides, or even the higher `-O3`.

I don’t know this really applies to you because while it’s very common for compiled languages to have a debug build that’s fast to compile (but slow at runtime), with Julia you’re more likely to not compile at all until you have your code ready for the final build. In principle the same principle applies for Julia, in case you compile often.

---

<div class="post-metadata">

**Author:** ![Pablo](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Pablo](https://discourse.julialang.org/u/Pablo)\
**Post date:** [February 28, 2023, 10:46am UTC](https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274/3 "2023-02-28T10:46:19Z")

</div>

Thanks for the reply

I do compile often

I’ve changed the optimization level to 0 as described in here:

> [@Change Optimization Level in VS Code?](https://discourse.julialang.org/t/change-optimization-level-in-vs-code/48966/2):
>
> If you go to the extension settings of the Julia extension, you see on top “Additional Args”. Edit this in settings.json and change it, that it looks like: ..., "julia.additionalArgs": ["--optimize=0"], ..., Of course without the … lines and with your desired level 0,1,2 or 3.

I didn’t find much of a difference however

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [February 28, 2023, 1:16pm UTC](https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274/4 "2023-02-28T13:16:49Z")

</div>

I wouldn’t rule it out as effective, until you tried it the right way. 🙂 It’s just a theory that this will help though.

It’s documented here:

> <https://github.com/JuliaLang/PackageCompiler.jl/blob/df3543443b8b5740150e28a5638f7c635c2c61eb/src/PackageCompiler.jl#L746>

I would it even try with `--compile=min -O0 --inline=no --min-optlevel=0 --check-bounds=no`

The reason for this way of invoking optimization and other option, is as I suspected, PackageCompiler.jl starts from your julia (with yes, the opt settings you chose, there would only slow down, and you might argue for higher settings, this setting might influence compilation speed (only minimally?), but likely not the resulting binary), but I think it must invoke a new julia as a sub-process, and I’m not sure they inherit the opt settings (probably in some cases, e.g. when using Distributed), here at least you can set it explicitly (to something different), and that setting will affect the opt level of the generated app, plus hopefully the compilation speed.

When I want maximum startup-speed of Julia, I do use `--compile=min` and min actually means no compilation (the interpreter rater used), so I’m not sure if this actually works for you, try also skipping it and `--check-bounds=no` which would likely at best provide a minimal speed-up. I think adding bounds checks must be rather fast, and recommended (it’s the default, “auto”, you may want “yes”).

Another option, and you could combine them, is choosing a incremental sysimage build. Non-incremental in the default (70 MB smaller), but likely slower since you actually have to build the sysimage then…

> **[Apps · PackageCompiler](https://julialang.github.io/PackageCompiler.jl/dev/apps.html#Incremental-vs-non-incremental-sysimage)**
>
> Documentation for PackageCompiler.

> <https://github.com/JuliaLang/PackageCompiler.jl/issues/506>
>
> Given sysimage generation isn't as time sensitive, the user may wish to make com…pilation try harder to optimize than the package allows due to module-specific max opt levels.
> 
> The new flag \`--min-optlevel\` added in https://github.com/JuliaLang/julia/pull/39536 allows setting a minimum opt level to override these.
> 
> Perhaps a kwarg could be provided to set this, if the user desires?

---

<div class="post-metadata">

**Author:** ![Pablo](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Pablo](https://discourse.julialang.org/u/Pablo)\
**Post date:** [March 3, 2023, 5:09pm UTC](https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274/5 "2023-03-03T17:09:01Z")

</div>

Thank you for clarifying.

In the end I went with this:

```
julia --project=. -e 'using PackageCompiler; create_app("./",".prodcontainer/compiled_app",force=true, filter_stdlibs=false, incremental=true, sysimage_build_args=`--compile=min -O0 --min-optlevel=0 --inline=no --check-bounds=no`)'

```

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [March 9, 2023, 2:16pm UTC](https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274/6 "2023-03-09T14:16:41Z")

</div>

I would check with Julia master, since this was merged:

> <https://github.com/JuliaLang/julia/pull/47797#issuecomment-1456887255>
>
> \[From 454 seconds\](https://buildkite.com/julialang/julia-master/builds/21690#018…6b860-0fcd-4f0e-ac5f-a5b1850eb372/645-2567) to \[67 seconds\](https://buildkite.com/julialang/julia-master/builds/21691#0186b870-42c3-4e19-bcd1-a7d4a58bda85/659-2581), in one fell swoop, you've reduced overall build CI times by 30%. (The assert build is even more impressive, from \[700 seconds\](https://buildkite.com/julialang/julia-master/builds/21690#0186b860-154c-457d-a571-db56ed79c36b/661-2583) to \[101 seconds\](https://buildkite.com/julialang/julia-master/builds/21691#0186b870-573a-4981-a4e8-9f555f865091/639-2561) ).
> 
> The buildbots salute you sir.
> 
> !\[buildbot salute\](https://i.giphy.com/3mfxH0nbfVFLt1gTpq.gif)

> This reduces the Outputting sysimage file… portion from 142s to 20s for me, using 32 cores.

> [From 454 seconds](https://buildkite.com/julialang/julia-master/builds/21690#0186b860-0fcd-4f0e-ac5f-a5b1850eb372/645-2567) to [67 seconds](https://buildkite.com/julialang/julia-master/builds/21691#0186b870-42c3-4e19-bcd1-a7d4a58bda85/659-2581), in one fell swoop, you’ve reduced overall build CI times by 30%. (The assert build is even more impressive, from [700 seconds](https://buildkite.com/julialang/julia-master/builds/21690#0186b860-154c-457d-a571-db56ed79c36b/661-2583) to [101 seconds](https://buildkite.com/julialang/julia-master/builds/21691#0186b870-573a-4981-a4e8-9f555f865091/639-2561) ).

I think it should help, if you need to generate a sysimage (which is the default, another option is non-incremental).

---

<div class="post-metadata">

**Author:** ![Pablo](https://avatars.discourse-cdn.com/v4/letter/p/ad7895/32.png) [@Pablo](https://discourse.julialang.org/u/Pablo)\
**Post date:** [March 15, 2023, 8:41am UTC](https://discourse.julialang.org/t/shorten-time-to-create-app-using-packagecompiler/95274/7 "2023-03-15T08:41:22Z")

</div>

I have noticed an significant reduction in time to create\_app(), to almost half. Must be what you shared
