Why does Pkg.activate(".") require compilation? Time to first project activation

mkitti
Wed, 05 Jul 2023 02:34:32 +0000
Performance

Pkg.activate(".") seems to to take about 200 milliseconds, mostly due to compilation. It still takes 40 milliseconds even after activating the same environment again.

$ julia -e 'using Pkg; for i in 1:5; @time Pkg.activate("."); end'
  Activating project at `~/.julia/dev/ScriptUtils`
  0.220025 seconds (232.01 k allocations: 16.980 MiB, 98.52% compilation time)
  Activating project at `~/.julia/dev/ScriptUtils`
  0.042125 seconds (81.89 k allocations: 5.737 MiB, 95.17% compilation time)
  Activating project at `~/.julia/dev/ScriptUtils`
  0.001953 seconds (3.73 k allocations: 414.523 KiB)
  Activating project at `~/.julia/dev/ScriptUtils`
  0.001633 seconds (3.73 k allocations: 414.180 KiB)
  Activating project at `~/.julia/dev/ScriptUtils`
  0.001591 seconds (3.73 k allocations: 414.086 KiB)

I thought perhaps the second round of compilation had to due with the environment changing. Even if I initialize Julia with the correct environment these compilation times persist.

$ julia --project=. -e 'using Pkg; for i in 1:5; @time Pkg.activate("."); end'
  Activating project at `~/.julia/dev/ScriptUtils`
  0.219066 seconds (231.95 k allocations: 16.975 MiB, 98.48% compilation time)
  Activating project at `~/.julia/dev/ScriptUtils`
  0.051085 seconds (81.89 k allocations: 5.737 MiB, 95.46% compilation time)
  Activating project at `~/.julia/dev/ScriptUtils`
  0.001949 seconds (3.73 k allocations: 414.492 KiB)
  Activating project at `~/.julia/dev/ScriptUtils`
  0.001591 seconds (3.73 k allocations: 414.148 KiB)
  Activating project at `~/.julia/dev/ScriptUtils`
  0.001618 seconds (3.73 k allocations: 414.055 KiB)

If I want to simplify usage of Julia code from the command line via an executable script, a Pkg.activate call is usually one of the first tasks.

Are we not precompiling Pkg.activate(::String) into the system image?

3 posts - 1 participant