# How to reuse julia compiled cache across machines?

**URL:** https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149
**Category:** Performance
**Tags:** question, pkg
**Created:** [July 17, 2024, 3:19pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149 "2024-07-17T15:19:52Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [July 17, 2024, 3:19pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/1 "2024-07-17T15:19:52Z")

</div>

Hello,

I’d like to cache the julia package compilation in an external volume which can be read and written to by multiple clients (using a respective kubernetes volume) .

My question is whether it is enough to bring the `.julia/compile` folder to this special volume, or whether something else, e.g. if the lockfile resides somewhere else, needs to be brought there too.

Thanks to the following two julia additions I hope this works in principle since 1.10

- [precompile: respect and report cache pidlocking by IanButterworth · Pull Request #3519 · JuliaLang/Pkg.jl · GitHub](https://github.com/JuliaLang/Pkg.jl/pull/3519)
- [pidlock cache file precompilation by IanButterworth · Pull Request #49052 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/49052)

---

<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: [July 17, 2024, 4:20pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/2 "2024-07-17T16:20:09Z")

</div>

It should just work as you describe.

---

<div class="post-metadata">

### Author: ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)
#### Post date: [July 17, 2024, 5:52pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/3 "2024-07-17T17:52:14Z")

</div>

Modulo different CPU architectures across the clients. You might want to set `JULIA_CPU_TARGET` appropriately

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [July 17, 2024, 8:55pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/4 "2024-07-17T20:55:28Z")

</div>

thanks for the hint 👍

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [August 13, 2024, 4:22pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/5 "2024-08-13T16:22:02Z")

</div>

I tried this now but experience recompilation despite the compiled directory being reconstructed. I guess another directory is needed somehow for caching compilation to work…

Does someone know which other package is needed? Or how to debug?

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [August 13, 2024, 4:59pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/6 "2024-08-13T16:59:00Z")

</div>

It seems that it is due to mtime changes inside `.julia/packages` looking into the code it seems that in principle julia has different ways of caching

> <https://github.com/JuliaLang/julia/blob/b7aa5e37402e2a0c81f9f2b80e89cf0f85ff6da6/base/loading.jl#L3828-L3855>

the mtime way is only one, the other being hash based, which would be better here for central caching.

Does someone know what needs to be set/available for precompilation to use hash for identification?

EDIT: I think I understood that just some packages specify explicitly to use `mtime` instead of hash by specifying `include_dependency("myexternal.file", track_content=false)`. Hence it is indeed necessary to also backup the `packages` subdirectory for caching to work.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [August 13, 2024, 5:55pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/7 "2024-08-13T17:55:45Z")

</div>

This should work better in Julia 1.11 (not yet released), for example because of [Avoid repeated precompilation when loading from non-relocatable cachefiles by fatteneder · Pull Request #53905 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/53905) .

---

<div class="post-metadata">

### Author: ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)
#### Post date: [August 13, 2024, 8:12pm UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/8 "2024-08-13T20:12:07Z")

</div>

To load the caches you need `compiled` and `packages`.

Hash identification only works with 1.11 onwards, and that is needed to allow moving the `compiled` folder.

To debug re-precompilation issues run Julia with the environment variable `JULIA_DEBUG=loading`.

`include_dependency("myexternal.file", track_content=true)` is now the default.

Here are some notes on how to relocate pkgs on 1.11: [PSA: Cache relocation with Julia v1.11 - HackMD](https://hackmd.io/@Je8OcLYBQr2ociLAtslIug/BJvv7G9pa)

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [August 14, 2024, 10:54am UTC](https://discourse.julialang.org/t/how-to-reuse-julia-compiled-cache-across-machines/117149/9 "2024-08-14T10:54:55Z")

</div>

I know tried to symlink the `compiled` folder, which works, and also the `packages` folder to a cache directory, which unfortunately kind of does not work.  
It makes julia being super super super slow, like almost not responsive. Not sure what is going on…

EDIT: I think it is not because of the symlink but because of some characteristics of my remote filesystem which is not fully posix compliant or maybe slow for some things.
