Speeding up Class#new
summary
Reimplements Class#new in Ruby by adding two primitives — one to set the fcall flag on send and one to perform non‑monkey‑patchable allocation — and changing the compiler to inline YARV class_new at callsites with a guard. This removes C→Ruby frame switches and leverages inline caches. Benchmarks show single-arg allocation ~1.8× faster, keyword-heavy cases up to 6.2× faster, and at least 1.4× overall; memory rises ~122 bytes per callsite and the inlined approach changes stack traces by removing the class_new frame.
AI-written summary · about
chapters (20)
- 0:00Introduction to talk
- 1:47Why focus on Class#new
- 2:53Current Class#new implementation
- 4:17Inline caches explained
- 7:00Call time and VM speed
- 8:07Method search and inline cache
- 10:24Cache hits and misses
- 11:51Class#new in C and Ruby
- 14:06Call functions in Ruby and C
- 15:15Ruby’s call function
- 17:53Keyword arguments overhead
- 19:16First Ruby implementation attempt
- 20:39Primitive and fcall flag
- 21:47Monkey-patching and allocate
- 22:33New primitive for object assignment
- 23:19Inlining Class#new in Ruby
- 24:23Performance benchmarks
- 26:48Benchmark results analysis
- 27:30Summary and drawbacks
- 28:34Final summary and conclusion
related talks
40mImplementation Details of Ruby 2.0 VM
37mDown the rb_newobj() Rabbit Hole: Garbage Collection in Ruby
38mWhy I am excited about Ruby 2.1?
41mHigh Performance Ruby
33mUnderstanding Ruby's Method Cache
49mRabbit Hole: Garbage Collection and Ruby's Future
49mHow are Method Calls Formed?
39mPointers for Eliminating Heaps of Memory
