# V1.9-rc3 - faster precompilation with explicit \`precompile\` call?

**URL:** https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323
**Category:** Internals & Design
**Created:** [May 4, 2023, 2:22pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323 "2023-05-04T14:22:21Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [May 4, 2023, 2:22pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/1 "2023-05-04T14:22:21Z")

</div>

I have an internal package I’m using that is particularly slow to load on 1.9-rc3, on an AWS docker image (built locally, then deployed). Basically it’s just there to bring in all dependencies with some coordinating functions, which I use for my Pluto notebooks generally.

When I run `using MyPackage` alone, it takes ~9 min to complete.

However, if I call `import Pkg; Pkg.precompile(); using MyPackage`, the whole thing takes ~3 min to complete.

Is the difference that the former isn’t doing anything in parallel? If not, why not?

---

<div class="post-metadata">

### Author: ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)
#### Post date: [May 4, 2023, 2:28pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/2 "2023-05-04T14:28:01Z")

</div>

Yeah, that’s right, when just doing `using`, it’s not parallel. Indeed, on the master branch of Julia, this has been changed, and both will be executed in parallel.  
So why wasn’t it like that from the start? I don’t know. Perhaps it felt weird to spawn multiple Julia processes from Julia itself to handle precompilation.

---

<div class="post-metadata">

### Author: ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)
#### Post date: [May 4, 2023, 7:47pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/3 "2023-05-04T19:47:49Z")

</div>

> [@jakobnissen](#):
>
> Indeed, on the master branch of Julia, this has been changed, and both will be executed in parallel.

Unfortunately, this only helps in the specific case when `using` a single package involves compiling many dependencies. If instead of `using MyPackage` there is

```julia
using PkgA
using PkgB
using PkgC
...

```

then it’ll still be slower than running `]precompile`.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [May 4, 2023, 11:08pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/4 "2023-05-04T23:08:07Z")

</div>

> [@jakobnissen](#):
>
> So why wasn’t it like that from the start?

Because parallel precompilation is handled by Pkg, `using` is part of code loading which shouldn’t require Pkg at all. This has now been implemented with a Pkg hook, but the coupling between code loading and Pkg is still [not considered ideal](https://github.com/JuliaLang/julia/pull/49242#pullrequestreview-1369943161).

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [May 5, 2023, 11:51am UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/5 "2023-05-05T11:51:11Z")

</div>

I took the liberty of editing the title, since the question isn’t really about `loading` but more about how precompilation behaves implicitly under `using` vs explicit `precompile`.

I think the word “loading” should be reserved for how long a package takes to load _once_ it is already precompiled. I was quite alarmed by your number of 9min 😆 .

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [May 5, 2023, 12:08pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/6 "2023-05-05T12:08:16Z")

</div>

Fair! Though from a naive perspective, it all looks like it’s part of loading because there are no indicators of other activity.

One related confusion I had is why I couldn’t speed this up by precompiling during the Docker container setup, but it always needed to take this extra time on second run. I suppose it’s related to different CPU architecture of my machine vs. the Amazon machine?

---

<div class="post-metadata">

### Author: ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)
#### Post date: [May 5, 2023, 12:17pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/7 "2023-05-05T12:17:17Z")

</div>

Yes, we don’t support cross-compilation. It’s high on many people’s wish list but very nontrivial, so don’t hold your breath for it.

And as usual you raise an excellent point about there being no indication of what’s really happening. Assuming 1.10 retains the transition to parallel precompilation even for `using`, a fix is already in place. But if that gets reverted, we should probably add some visual indicator.

---

<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: [May 6, 2023, 12:17pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/8 "2023-05-06T12:17:55Z")

</div>

I’m confused. Are you not seeing the “Info: Precompiling…” message during this 9 minute period after using?

AFAIK that always shows if there’s any regular precompilation taking place

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [May 6, 2023, 1:06pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/9 "2023-05-06T13:06:35Z")

</div>

Not in the output lines displayed by AWS CloudWatch, pulled from the running container.

I do see it in the terminal when I manually run the container on AWS, connected by SSH.

EDIT: But I also do see the precompilation spinner lines when I explicitly call precompile.

---

<div class="post-metadata">

### Author: ![simsurace](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simsurace/32/30216_2.png) [@simsurace](https://discourse.julialang.org/u/simsurace)
#### Post date: [May 9, 2023, 9:35pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/10 "2023-05-09T21:35:28Z")

</div>

Can I ask you here for clarification? I‘m confused as to whether you are effectively saying that the —cpu-target flags are being ignored by precompilation.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [May 9, 2023, 11:32pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/11 "2023-05-09T23:32:23Z")

</div>

Cross-compilation meant as compiling for a different architecture. With `julia -C` you can choose a different microarchitecture (or ISA, Instruction Set Architecture) within the same architecture, that’s not cross-compilation (or not too much at least).

---

<div class="post-metadata">

### Author: ![simsurace](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simsurace/32/30216_2.png) [@simsurace](https://discourse.julialang.org/u/simsurace)
#### Post date: [May 10, 2023, 8:26am UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/12 "2023-05-10T08:26:59Z")

</div>

Oh ok. That‘s good to hear. Most often in cloud deployment we encounter different generations of x86\_64, that should work then? We are using cpu target flags and it seems to work so far.

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [May 10, 2023, 10:51am UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/13 "2023-05-10T10:51:02Z")

</div>

May I ask how you’re using it? Maybe that would work for me too, beacuse that sounds similar to mine.

---

<div class="post-metadata">

### Author: ![simsurace](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simsurace/32/30216_2.png) [@simsurace](https://discourse.julialang.org/u/simsurace)
#### Post date: [May 11, 2023, 11:37am UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/14 "2023-05-11T11:37:07Z")

</div>

We simply build a docker image in which we precompile with flags that may be more generic than the ones of the machine on which the docker image is built.

```julia
ENV JULIA_CPU_TARGET=x86_64;haswell;skylake;skylake-avx512

```

The idea is if we build with skylake-avx512, we still have code cached for skylake without avx512, and we can always fall back to the generic x86\_64. There may also occasionally be older haswell CPUs.

The reason we haven’t been using system images so far is that for our app the time to first response was higher compared to using package images & PrecompileTools. I haven’t yet understood why.

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [May 11, 2023, 12:13pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/15 "2023-05-11T12:13:43Z")

</div>

Thanks I’ll try that! How do you determine what targets to specify? Is this dark art documented somewhere?

---

<div class="post-metadata">

### Author: ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)
#### Post date: [May 11, 2023, 12:50pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/16 "2023-05-11T12:50:50Z")

</div>

The only piece of documentation that I know about this is here:

[https://docs.julialang.org/en/v1/devdocs/sysimg/#Specifying-multiple-system-image-targets](https://docs.julialang.org/en/v1/devdocs/sysimg/#Specifying-multiple-system-image-targets)

But TBH I don’t understand much of it, and I tend to always copy-paste the CPU target specification string mentioned there, in the hope that whatever has been chosen to build the official releases of Julia will be sufficiently portable for my use cases:

```
generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)

```

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [May 11, 2023, 6:07pm UTC](https://discourse.julialang.org/t/v1-9-rc3-faster-precompilation-with-explicit-precompile-call/98323/17 "2023-05-11T18:07:34Z")

</div>

Oh sweet, specifying this worked. I’m going to suggest the default JULIA\_CPU\_TARGET string be added to the official Docker images.
