
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.

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

#ruby #ruby3_5 #performance #yjit #rails #backend #programming #devlife