Project

General

Profile

Actions

Bug #22220

open

Performance 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

Added by emanuelevans (Emanuel Evans) 4 days ago. Updated about 12 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:126201]

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
Actions

Also available in: PDF Atom