June 3, 2025
If you’re like me and enjoy digging into Ruby performance, you’ll appreciate the latest improvements in Ruby 3.5 — especially when it comes to how fast objects get allocated.
Thanks to optimizations in Class#new, Ruby 3.5 dramatically improves allocation performance for both positional and keyword arguments. And with YJIT enabled, the numbers are even more impressive.
Here’s a simplified example from the benchmarks:
require "benchmark"
class Person
def initialize(name:, age:, city:)
@name = name
@age = age
@city = city
end
end
Benchmark.bm do |x|
x.report("allocating with keywords") do
1_000_000.times do
Person.new(name: "Jane", age: 32, city: "Rosario")
end
end
end
In Ruby 3.5, this runs up to 6.5x faster than in Ruby 3.4 when YJIT is enabled. That’s a major win for apps that create lots of objects — think Rails controllers, background jobs, serializers, etc.
It’s always fascinating to see low-level improvements like this pay off at the app level without needing to change any code.
Ruby 3.5 Brings Serious Speed to Object Allocation
Big thanks to @aaron Patterson and the Ruby team for the continued work on making Ruby not only expressive, but also fast.
Full write-up here: railsatscale.com/2025-05-21-fast-allocations-in-ruby-3-5
Top comments (0)