Closed appomsk closed 5 months ago
Can you try it with $RBENV_ROOT/versions/3.2.3/bin/ruby
? rbenv uses shell shims for invoking ruby or other related commands.
$ hyperfine "ruby -e 1"
Benchmark 1: ruby -e 1
Time (mean ± σ): 166.6 ms ± 143.7 ms [User: 37.1 ms, System: 20.4 ms]
Range (min … max): 113.8 ms … 575.1 ms 10 runs
$ hyperfine "~/.local/share/rbenv/versions/3.2.3/bin/ruby -e 1"
Benchmark 1: ~/.local/share/rbenv/versions/3.2.3/bin/ruby -e 1
Time (mean ± σ): 50.7 ms ± 38.0 ms [User: 26.6 ms, System: 13.2 ms]
Range (min … max): 39.6 ms … 187.9 ms 15 runs
Well. So it's shims... Just want Ruby to be a bit faster. I apologize for the anxiety. You can close the issue.
hyperfine '.rbenv/versions/3.2.4/bin/ruby -e 1'
Benchmark 1: .rbenv/versions/3.2.4/bin/ruby -e 1
Time (mean ± σ): 110.1 ms ± 2.8 ms [User: 84.5 ms, System: 25.1 ms]
Range (min … max): 107.3 ms … 118.5 ms 26 runs
hyperfine '/usr/bin/ruby -e 1'
Benchmark 1: /usr/bin/ruby -e 1
Time (mean ± σ): 106.7 ms ± 1.0 ms [User: 82.3 ms, System: 24.1 ms]
Range (min … max): 104.1 ms … 108.7 ms 27 runs
The slowness of rbenv as opposed to invoking a ruby
binary directly is known and documented (linked from the README): https://github.com/rbenv/rbenv/wiki/Comparison-of-version-managers
Just want Ruby to be a bit faster
100 ms for a process startup can indeed feel slow, but sometimes that can't be helped with the Ruby interpreter. Depending on your system resources, 50–100 ms might be a reasonable amount of startup time. On my machine, it's more like 30 ms.
If you want to further speed up Ruby, you can disable it loading Rubygems with --disable-gems
. Here it is on my Apple M1 machine:
$ hyperfine --warmup 5 '~/.rbenv/versions/3.2.2/bin/ruby --disable-gems -e 1'
Time (mean ± σ): 6.2 ms ± 0.4 ms [User: 3.6 ms, System: 2.1 ms]
Range (min … max): 5.8 ms … 7.6 ms 360 runs
Of course, a ruby interpreted started this way is less useful because it won't be able to load any gem dependenices.
Kubuntu 24.04. After building 3.3.1 on my pretty old machine and discovering that it's start is almost 10 times slower then python and almost 30 times slower then perl I decided to check it with version 3.2 and find out that ruby-build version is one and half time slower than system one. I belive it shouldn't be such. Ruby is already very slow.