~/talk

From Ruby 2 to 4: Updating a C extension for a Modern VM

Talkat RubyKaigi 2026 · 2026-04-22..04-24· [ruby]
slides:none on file

Datadog updates a C extension to target Ruby 4 APIs, replacing legacy patterns that slow GC and inflate memory. Practical swaps: use RB_ARRAY_ENTRY/RB_ARRAY_STORE instead of RArray pointers, use RB_HASH_ instead of RHash table ops, prefer FSTRING/dedup for long‑lived keys, and use rb_xmalloc/rb_xfree so Ruby can trigger GC on OOM. Replace data_wrap_struct with typeddata that implements write barriers, decompact* and memsize reporting. A polyfill layer targets modern APIs and falls back for older Rubies.

AI-written summary · about

  1. 0:00Introduction and background
  2. 3:14Why update C extensions
  3. 7:28Mechanical sympathy in Ruby
  4. 10:36Avoiding C when possible
  5. 11:18Array handling tips
  6. 13:25Hash handling tips
  7. 14:30String optimization with F strings
  8. 17:59Memory management best practices
  9. 20:28Avoiding immortal objects
  10. 21:30Typed data pitfalls
  11. 24:16Write barriers and compaction
  12. 26:04Type embeddable flag benefits
  13. 27:29Performance impact and future work
  14. 29:12Q&A and resources
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 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
?
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.