Actions
Bug #22220
openPerformance regression when requiring `aws-sdk-ec2` in Ruby 4.0.6
Bug #22220:
Performance regression when requiring `aws-sdk-ec2` in Ruby 4.0.6
Description
Ruby 4.0.6 introduced a large performance regression when loading aws-sdk-ec2 (~30s on my machine, compared to <1s for ruby 4.0.5). Script to reproduce:
for v in 4.0.5 4.0.6; do
docker run --rm ruby:$v-slim bash -c '
gem install --no-document aws-sdk-ec2 -v 1.402.0 >/dev/null 2>&1
ruby -e "t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
require \"aws-sdk-ec2\"
printf(\"ruby %s: %.2fs\n\", RUBY_VERSION, Process.clock_gettime(Process::CLOCK_MONOTONIC) - t)"'
done
It appears to be related to Shape.new and/or Class.new compile times; minimal reproduction:
for v in 4.0.5 4.0.6; do
docker run --rm ruby:$v-slim ruby -e '
src = "class Shape\n def self.new(**) = nil\nend\nmodule M\n" +
(1..16_000).map { |i| %( K_#{i} = Shape.new(name: "k#{i}")) }.join("\n") + "\nend\n"
File.write("/tmp/bench.rb", src)
t = Process.clock_gettime(Process::CLOCK_MONOTONIC)
RubyVM::InstructionSequence.compile_file("/tmp/bench.rb")
printf("ruby %s: %.2fs\n", RUBY_VERSION, Process.clock_gettime(Process::CLOCK_MONOTONIC) - t)'
done
Updated by luke-gru (Luke Gruber) 4 days ago
Seems caused by 1f473ed633a364f8c89b69a76adfb22a4bf21f96
Updated by luke-gru (Luke Gruber) about 13 hours ago
Updated by viralpraxis (Iaroslav Kurbatov) about 12 hours ago
Possibly fixed by https://github.com/ruby/ruby/pull/18181
Actions