# Seemingly unnecessary Precompilation with Julia 1.9 in a Docker container

**URL:** <https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892>\
**Category:** General Usage\
**Tags:** precompilation, cloud-computing, docker\
**Created:** [June 5, 2023, 1:43pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892 "2023-06-05T13:43:03Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [June 5, 2023, 1:43pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/1 "2023-06-05T13:43:03Z")

</div>

I have a Julia web server running within a Docker container. Everything used to run fine with Julia 1.8.3. I’m trying to upgrade to Julia 1.9, and now it seems the server takes too much time to start when I deploy it. It runs fine locally, the server starts quickly. Looking at the remote log messages, it seems that Julia is precompiling my package, what might explain the long startup time. I don’t see any precompilation running the container locally, though.

What could be triggering precompilation again when this container runs remotely?

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [June 5, 2023, 1:54pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/2 "2023-06-05T13:54:28Z")

</div>

Maybe if it is not the same hardware architecture on the server?

---

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [June 6, 2023, 7:05am UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/3 "2023-06-06T07:05:52Z")

</div>

Great point, thanks! Well they are all x86, but my local machine Sys.CPU\_NAME is `tigerlake` and the remote is a slightly older `skylake` familiy chip… I suppose this could be enough to cause a conflict?

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [June 6, 2023, 9:21am UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/4 "2023-06-06T09:21:09Z")

</div>

Maybe, I don’t really know much about this. But since they cache lower level stuff in precompilation for 1.9 (iiuc) it seems like it could maybe be affected.

---

<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:** [June 6, 2023, 10:24am UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/5 "2023-06-06T10:24:32Z")

</div>

If you run Julia with `JULIA_DEBUG=loading` in the docker container you will get logs for why the caches were rejected.

If it is indeed due to architecture (it could be due to other things such as bounds checking being on vs. off etc.), you can do the following:  
In the Dockerfile before installing/precompiling your package, try to insert a line

```plaintext
ENV JULIA_CPU_TARGET=x86_64;haswell;skylake;skylake-avx512;tigerlake

```

that should cover most architectures that you may encounter, including yours.  
I’d be interested to hear back whether this works out.

---

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [June 6, 2023, 3:30pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/6 "2023-06-06T15:30:31Z")

</div>

Thanks for the info, I tried that but still got the pre-compilation message and the timeout as before. I’m going to try looking at the debug logs now.

---

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [June 6, 2023, 3:43pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/8 "2023-06-06T15:43:16Z")

</div>

The log shows lots of messages like

```julia
┌ Debug: Rejecting cache file /home/app/.julia/compiled/v1.9/MyPackageXxx/iqN7A_LVvhN.ji for MyPackageXxx [7-09790-790-7-9-789-] since pkgimage can't be loaded on this target"
└ @ Base loading.jl:2706
...

```

I was now running without the `JULIA_CPU_TARGET`, will put that back on and see if it’s the same thing.

---

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [June 6, 2023, 4:26pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/9 "2023-06-06T16:26:58Z")

</div>

I have now tried simply `JULIA_CPU_TARGET=generic` and still got the same thing… Are there other simple things I could try just setting up flags and variables like that?

---

<div class="post-metadata">

**Author:** ![nrontsis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nrontsis/32/38535_2.png) [@nrontsis](https://discourse.julialang.org/u/nrontsis)\
**Post date:** [June 6, 2023, 4:29pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/10 "2023-06-06T16:29:24Z")

</div>

I also saw seemingly unnecessary precompilations with Julia 1.9 as compared to 1.8.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [June 6, 2023, 4:53pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/11 "2023-06-06T16:53:23Z")

</div>

Weird, that helped me in this case [`compilecache` failed when `@everywhere using` from remote machines · Issue #48217 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/48217#issuecomment-1554602976)

---

<div class="post-metadata">

**Author:** ![sbuercklin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sbuercklin/32/15728_2.png) [@sbuercklin](https://discourse.julialang.org/u/sbuercklin)\
**Post date:** [June 6, 2023, 7:09pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/12 "2023-06-06T19:09:02Z")

</div>

I wasn’t able to find a reference for `JULIA_CPU_TARGET` other than this issue: [JULIA\_CPU\_TARGET flag · Issue #8198 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/8198)

Are the valid values for `JULIA_CPU_TARGET` still whatever the valid architectures are for `gcc --march`? Is there a more Julia-focused documentation of the precompilation-relevant flags?

E- looked further into the manual, found it here: [System Image Building · The Julia Language](https://docs.julialang.org/en/v1/devdocs/sysimg/#Specifying-multiple-system-image-targets)

---

<div class="post-metadata">

**Author:** ![nrontsis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nrontsis/32/38535_2.png) [@nrontsis](https://discourse.julialang.org/u/nrontsis)\
**Post date:** [June 6, 2023, 8:43pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/13 "2023-06-06T20:43:15Z")

</div>

I was also having [issues](https://discourse.julialang.org/t/packagecompiler-cpu-target-silently-fails-to-create-image-for-specified-architecture/99954) with system image building 🙈

---

<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:** [June 6, 2023, 9:14pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/14 "2023-06-06T21:14:48Z")

</div>

The flags are not specific to precompilation i.e. package images, and indeed I‘m not sure this (precompilation to targets other than native) is documented.

However, the possible flags can be found with `julia —cpu-target=help`.

---

<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:** [June 6, 2023, 9:17pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/15 "2023-06-06T21:17:29Z")

</div>

Bummer. I don‘t know for sure. I discussed this with @Sukera on Slack once, maybe he has other suggestions.

---

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [June 7, 2023, 7:29am UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/16 "2023-06-07T07:29:15Z")

</div>

Thanks for pointing that out. I have tried `generic` and still got the same issue. Could this be a bug? I’m not sure how can I narrow down what causes the cache invalidation.

---

<div class="post-metadata">

**Author:** ![nrontsis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nrontsis/32/38535_2.png) [@nrontsis](https://discourse.julialang.org/u/nrontsis)\
**Post date:** [June 7, 2023, 5:41pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/17 "2023-06-07T17:41:54Z")

</div>

[I opened an issue in Julia about this with a minimal reproducible example](https://github.com/JuliaLang/julia/issues/50102). This also includes a minimal example for [this related issue that I mentioned before](https://discourse.julialang.org/t/packagecompiler-cpu-target-silently-fails-to-create-image-for-specified-architecture/99954).

---

<div class="post-metadata">

**Author:** ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)\
**Post date:** [June 8, 2023, 4:28pm UTC](https://discourse.julialang.org/t/seemingly-unnecessary-precompilation-with-julia-1-9-in-a-docker-container/99892/18 "2023-06-08T16:28:30Z")

</div>

Thanks @nrontsis! So setting JULIA\_CPU\_TARGET does seem the be the workaround, the issue I had was having to set it up earlier in the Dockerfile, so that it affects every call to Julia. See [Cache invalidations in precompiled code · Issue #50102 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/50102)
