Ruby ten times slower as a global command
Checks
-
[x] I have checked that this issue has not already been reported.
-
[x] I have confirmed this bug exists on the latest version of pixi, using
pixi --version.
Reproducible example
pixi global install ruby
pixi global install python
pixi global install hyperfine
hyperfine --warmup 3 "/Users/ian/.pixi/bin/ruby -e 'puts \"Ruby Hello\"'"
hyperfine --warmup 3 "/Users/ian/.pixi/envs/ruby/bin/ruby -e 'puts \"Ruby Hello\"'"
hyperfine --warmup 3 "/Users/ian/.pixi/bin/python -c 'print(\"Python Hello\")'"
hyperfine --warmup 3 "/Users/ian/.pixi/envs/python/bin/python -c 'print(\"Python Hello\")'"
Issue description
Running ruby results in 355ms time vs. 29.6ms when run from the enviroment bin directory directly. Python for comparison shows roughly the same performance.
ε ➪ hyperfine --warmup 3 "/Users/ian/.pixi/bin/ruby -e 'puts \"Ruby Hello\"'"
Benchmark 1: /Users/ian/.pixi/bin/ruby -e 'puts "Ruby Hello"'
Time (mean ± σ): 355.7 ms ± 7.5 ms [User: 126.6 ms, System: 207.4 ms]
Range (min … max): 351.1 ms … 376.9 ms 10 runs
ε ➪ hyperfine --warmup 3 "/Users/ian/.pixi/envs/ruby/bin/ruby -e 'puts \"Ruby Hello\"'"
Benchmark 1: /Users/ian/.pixi/envs/ruby/bin/ruby -e 'puts "Ruby Hello"'
Time (mean ± σ): 29.6 ms ± 0.4 ms [User: 24.7 ms, System: 4.4 ms]
Range (min … max): 28.2 ms … 30.8 ms 92 runs
ε ➪ hyperfine --warmup 3 "/Users/ian/.pixi/bin/python -c 'print(\"Python Hello\")'"
Benchmark 1: /Users/ian/.pixi/bin/python -c 'print("Python Hello")'
Time (mean ± σ): 10.3 ms ± 0.2 ms [User: 7.4 ms, System: 2.2 ms]
Range (min … max): 9.8 ms … 11.1 ms 228 runs
ε ➪ hyperfine --warmup 3 "/Users/ian/.pixi/envs/python/bin/python -c 'print(\"Python Hello\")'"
Benchmark 1: /Users/ian/.pixi/envs/python/bin/python -c 'print("Python Hello")'
Time (mean ± σ): 8.2 ms ± 0.2 ms [User: 6.6 ms, System: 1.2 ms]
Range (min … max): 7.8 ms … 8.7 ms 274 runs
Expected behavior
Ruby should be the same speed no matter where it is run from...
Awesome, thank you for the benchmark! We are actually currently working on a slightly adjusted way of launching the executables. The new way caches the activation variables and so it should be faster. This will be helpful.
cc @nichmor maybe you can run this locally?
It does seem this might just be lots of conda cruft:
ε ➪ cat .pixi/bin/ruby
1 #!/bin/sh
2 export PATH="/Users/ian/.pixi/envs/ruby/bin:${PATH}"
3 export CONDA_PREFIX="/Users/ian/.pixi/envs/ruby"
4 . "/Users/ian/.pixi/envs/ruby/etc/conda/activate.d/activate-gfortran_osx-arm64.sh"
5 . "/Users/ian/.pixi/envs/ruby/etc/conda/activate.d/activate_clang_osx-arm64.sh"
6 . "/Users/ian/.pixi/envs/ruby/etc/conda/activate.d/activate_clangxx_osx-arm64.sh"
7 . "/Users/ian/.pixi/envs/ruby/etc/conda/activate.d/libxml2_activate.sh"
8 . "/Users/ian/.pixi/envs/ruby/etc/conda/activate.d/ruby_activate.sh"
9 "/Users/ian/.pixi/envs/ruby/bin/ruby" "$@"
If I comment out lines 4-7 then ruby takes ~33ms, much better!
ε ◎ hyperfine --warmup 3 "/Users/ian/.pixi/bin/ruby -e 'puts \"Ruby Hello\"'"
Benchmark 1: /Users/ian/.pixi/bin/ruby -e 'puts "Ruby Hello"'
Time (mean ± σ): 33.1 ms ± 0.4 ms [User: 26.1 ms, System: 5.9 ms]
Range (min … max): 31.8 ms … 34.0 ms 84 runs
Benchmarks results using new way of launching executables:
hyperfine --warmup 3 "/Users/graf/.pixi/bin/ruby -e 'puts \"Ruby Hello\"'"
Benchmark 1: /Users/graf/.pixi/bin/ruby -e 'puts "Ruby Hello"'
Time (mean ± σ): 33.2 ms ± 0.7 ms [User: 26.3 ms, System: 5.8 ms]
Range (min … max): 31.9 ms … 34.6 ms 85 runs
hyperfine --warmup 3 "/Users/graf/.pixi/envs/ruby/bin/ruby -e 'puts \"Ruby Hello\"'"
Benchmark 1: /Users/graf/.pixi/envs/ruby/bin/ruby -e 'puts "Ruby Hello"'
Time (mean ± σ): 32.0 ms ± 0.8 ms [User: 25.7 ms, System: 5.3 ms]
Range (min … max): 30.5 ms … 34.4 ms 84 runs
I think by switching to the new way of launching them we will avoid this slow problem
Hi, just tested the released 0.35 which has https://github.com/prefix-dev/pixi/pull/2381 and can confirm ruby, python, lua and pandoc at least are all now only a few ms separated between the global launcher and actual program. Thanks @nichmor, awesome work!!!
Awesome! Btw. ruby 3.3.6 was also released on conda-forge - hope it works well for you! :)