~/talk

Speeding up Class#new

Talkat RubyKaigi 2025 · 2025-04-16..04-18· [ruby]
slides:none on file

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

  1. 0:00Introduction to talk
  2. 1:47Why focus on Class#new
  3. 2:53Current Class#new implementation
  4. 4:17Inline caches explained
  5. 7:00Call time and VM speed
  6. 8:07Method search and inline cache
  7. 10:24Cache hits and misses
  8. 11:51Class#new in C and Ruby
  9. 14:06Call functions in Ruby and C
  10. 15:15Ruby’s call function
  11. 17:53Keyword arguments overhead
  12. 19:16First Ruby implementation attempt
  13. 20:39Primitive and fcall flag
  14. 21:47Monkey-patching and allocate
  15. 22:33New primitive for object assignment
  16. 23:19Inlining Class#new in Ruby
  17. 24:23Performance benchmarks
  18. 26:48Benchmark results analysis
  19. 27:30Summary and drawbacks
  20. 28:34Final summary and conclusion
~/search
type to search 8,222 conferences, 162,397 speakers and 219,688 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
← →
on a talk: 5 seconds back / forward
0–9
on a talk: jump to 0%–90% of the recording
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.