Hasty Briefsbeta

Bilingual

Fast Allocations in Ruby 3.5

a year ago
  • #Optimization
  • #Performance
  • #Ruby
  • Ruby 3.5 introduces significant speed improvements in object allocation, making it up to six times faster.
  • Benchmarks compare positional and keyword parameters with and without YJIT, showing consistent speedups.
  • Positional parameters see a 1.8x speedup without YJIT and 2.3x with YJIT, regardless of parameter count.
  • Keyword parameters show increasing speedups with more parameters, up to 3x without YJIT and over 6.5x with YJIT.
  • The optimization involves inlining the `Class#new` method, eliminating stack frames and parameter copies.
  • Inlining improves inline cache hits and reduces overhead by avoiding conversions between Ruby and C calling conventions.
  • A downside is a small backward incompatibility where the `Class#new` frame is missing in stack traces.
  • Memory usage increases slightly due to more instructions at call sites, but the impact is minimal (0.5% growth in instruction sequence size).