# Why using \`\`\] test package\`\` recompiles the package again?

**URL:** https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393
**Category:** General Usage
**Tags:** question, testing, precompilation
**Created:** [March 21, 2023, 1:08pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393 "2023-03-21T13:08:44Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [March 21, 2023, 1:08pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/1 "2023-03-21T13:08:44Z")

</div>

I’ve had this experience many times but now just installed a package from scratch. All worked as expected (maybe except the very long time), packaged installed and and compiled. Next I run the tests and … recompiled the package again. Why is that? And I further noticed that there are now two sets of files in `compiled/v1.9/package` with different sizes

---

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [March 21, 2023, 2:48pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/2 "2023-03-21T14:48:23Z")

</div>

Are you using additional test dependencies? This might introduce recompilation of the package

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [March 21, 2023, 3:11pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/3 "2023-03-21T15:11:13Z")

</div>

`Pkg.test` uses `--check-bounds=yes`, which is incompatible with the precompilation image that was generated during package installation.

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [March 21, 2023, 3:43pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/4 "2023-03-21T15:43:16Z")

</div>

Thanks, but would you mind elaborating a bit more?  
When developing the package I often restart Julia to force recompilation. If I run the tests immediately after `using GMT` (where a recompilation takes place), it **always** recompiles GMT again. This is no package installation. Sorry, but I don’t find this normal.

---

<div class="post-metadata">

### Author: ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)
#### Post date: [March 21, 2023, 5:03pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/5 "2023-03-21T17:03:09Z")

</div>

For me it worked fine, but maybe I did not follow the same workflow you have?

Installing, then precompiling, then precompiling test environment, then testing

```julia
stefan@cube ~> julia --project=(mktemp -d) -tauto
(tmp.byjxPCUpkb) pkg> dev --local GMT
     Cloning git-repo `https://github.com/GenericMappingTools/GMT.jl.git`
   Resolving package versions...
    Updating `/tmp/tmp.byjxPCUpkb/Project.toml`
  [5752ebe1] + GMT v0.44.6 `dev/GMT`
    Updating `/tmp/tmp.byjxPCUpkb/Manifest.toml`
    ...
    Building GMT → `/tmp/tmp.byjxPCUpkb/dev/GMT/deps/build.log`

(tmp.byjxPCUpkb) pkg> test GMT
     Testing GMT
      Status `/tmp/jl_PnSTfU/Project.toml`
      ...
      Status `/tmp/jl_PnSTfU/Manifest.toml`
      ...
Precompiling environment...
  6 dependencies successfully precompiled in 112 seconds. 18 already precompiled.

     Testing Running tests...
Test Summary: | Pass Total Time
GMT | 1 1 0.1s
     Testing GMT tests passed 

```

and starting it again in a new julia process (it did not trigger precompilation)

```julia
stefan@cube ~> julia --project=/tmp/tmp.byjxPCUpkb -tauto
(tmp.byjxPCUpkb) pkg> test GMT
     Testing GMT
      Status `/tmp/jl_aLRnm5/Project.toml`
      ...
      Status `/tmp/jl_aLRnm5/Manifest.toml`
      ...
     Testing Running tests...
Test Summary: | Pass Total Time
GMT | 1 1 0.1s
     Testing GMT tests passed 

```

on

```julia
julia> versioninfo()
Julia Version 1.10.0-DEV.834
Commit 66c58505e90 (2023-03-19 15:18 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 1700 Eight-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, znver1)
  Threads: 16 on 16 virtual cores

```

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [March 21, 2023, 5:59pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/6 "2023-03-21T17:59:22Z")

</div>

I think the difference is that your attempt didn’t really installed the GMT binaries, that’s why you got the (nothing actually tested)

```julia
Test Summary: | Pass Total Time
GMT | 1 1 0.1s

```

I am testing a new JLL solution but there are mysterious errors between OSs  
For example this is what I get in a MacOS Big Sur (but would be the same in Linux)

```julia
(@v1.9) pkg> up
    Updating registry at `~/.julia/registries/General`
    Updating git-repo `https://github.com/JuliaRegistries/General.git`
    Updating git-repo `https://github.com/GenericMappingTools/GMT.jl.git`
    Updating `~/.julia/environments/v1.9/Project.toml`
  [5752ebe1] ~ GMT v0.44.6 `https://github.com/GenericMappingTools/GMT.jl.git#GMT_jll` ? v0.44.6 `https://github.com/GenericMappingTools/GMT.jl.git#GMT_jll`
    Updating `~/.julia/environments/v1.9/Manifest.toml`
  [5752ebe1] ~ GMT v0.44.6 `https://github.com/GenericMappingTools/GMT.jl.git#GMT_jll` ? v0.44.6 `https://github.com/GenericMappingTools/GMT.jl.git#GMT_jll`
    Building GMT ? `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/795e50b2f3064632d01f54d700187e5982c2a266/build.log`
Precompiling environment...
  1 dependency successfully precompiled in 119 seconds. 87 already precompiled.

(@v1.9) pkg> 

julia> 
Joaquims-MacBook-Pro:mironeGIT j$ julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.9.0-rc1 (2023-03-07)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using GMT

(@v1.9) pkg> test GMT
     Testing GMT
      Status `/private/var/folders/yz/zrrm34bx14b0myqpl1848qdr0000gn/T/jl_ch8DX8/Project.toml`
  [5752ebe1] GMT v0.44.6 `https://github.com/GenericMappingTools/GMT.jl.git#GMT_jll`
  [08abe8d2] PrettyTables v2.2.3
  [bd369af6] Tables v1.10.1
  [3f19e933] p7zip_jll v17.4.0+0 `@stdlib/p7zip_jll`
        Info Packages marked with ? have new versions available but compatibility constraints restrict them from upgrading.
Precompiling environment...
  Progress [>] 0/1
  ? GMT
...
...

```

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [March 21, 2023, 6:05pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/7 "2023-03-21T18:05:17Z")

</div>

> [@joa-quim](#):
>
> When developing the package I often restart Julia to force recompilation. If I run the tests immediately after `using GMT` (where a recompilation takes place), it **always** recompiles GMT again. This is no package installation. Sorry, but I don’t find this normal.

Start Julia with `--check-bounds=yes`.  
Precompilation images in Julia 1.9 with `--check-bounds=yes` and `--check-bounds=no` are incompatible, so you need separate precompilations for both.

This was not the case in Julia 1.8. @Krastanov, which version of Julia are you using?

---

<div class="post-metadata">

### Author: ![Krastanov](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krastanov/32/6817_2.png) [@Krastanov](https://discourse.julialang.org/u/Krastanov)
#### Post date: [March 21, 2023, 6:08pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/8 "2023-03-21T18:08:53Z")

</div>

nightly; added to the post above

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [March 21, 2023, 6:33pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/9 "2023-03-21T18:33:09Z")

</div>

> [@Elrod](#):
>
> Precompilation images in Julia 1.9 with `--check-bounds=yes` and `--check-bounds=no` are incompatible,so you need separate precompilations for both.

Does not sound good to me. We’ll all end up with dozens of _repeated_ precompiled files … and for some packages they are not exactly small in \>=1.9

---

<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: [March 21, 2023, 6:57pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/10 "2023-03-21T18:57:16Z")

</div>

There’s no good way around it. Bounds-checking is implemented in the compiler: when it’s on, it generates different code than when it’s off. Since Julia 1.9 saves the compiled code, the mode you compile in matters: you can’t just change the mode after compilation is complete.

But that means you need to compile twice: once with bounds-checking on, and once with bounds-checking off. Now, we could do that up-front, but that would ~double the compilation time in many cases where the user never has any intention of running the tests. So better is to precompile once with default settings, and then when running tests we have to recompile (if the up-to-date source code has not already been compiled with `--check-bounds=yes`).

Compiling C is little different: want both `-O0` and `-O3`? You have to compile twice.

If the amount of compilation time is annoying, and if you’re using SnoopPrecompile, consider turning it off in your local package dev environment: [PSA for SnoopPrecompile: turning off extra workload for specific packages - #5 by tim.holy](https://discourse.julialang.org/t/psa-for-snoopprecompile-turning-off-extra-workload-for-specific-packages/92865/5)

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [March 21, 2023, 7:03pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/11 "2023-03-21T19:03:32Z")

</div>

> [@tim.holy](#):
>
> Compiling C is little different: want both `-O0` and `-O3`? You have to compile twice.

Perhaps a difference is that when developing C++, I’m basically only compiling with `-O0`, sanitizers, debug information, and assertions.  
Perhaps we should also have the habit of generally developing Julia under `--check-bounds=yes`, etc.

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [March 21, 2023, 8:30pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/12 "2023-03-21T20:30:27Z")

</div>

Also, as inference often takes the bulk of the compile time, I’d also like more options to weaken inference results.  
Something like this: [Comparing JuliaLang:master...YingboMa:myb/concrete\_only · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/compare/master...YingboMa:julia:myb/concrete_only)  
It has two benefits:

1. Improving compile times.
2. It doesn’t decrease the performance ceiling of optimal code, unlike options like `-O1`. Instead, it makes suboptimal and bad code worse and more obvious. Thus, it’s actually easier to optimize code, which isn’t worth doing with `-O1` or lower levels.

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [December 16, 2024, 6:20pm UTC](https://discourse.julialang.org/t/why-using-test-package-recompiles-the-package-again/96393/13 "2024-12-16T18:20:10Z")

</div>

2 posts were split to a new topic: [How to speed up re-running tests?](https://discourse.julialang.org/t/how-to-speed-up-re-running-tests/123894)
