updating a c extension for a modern vm
I’ve often blogged about doing weird things to the Ruby VM using C extensions and Ruby’s C extension API, such as what we can learn about our apps or how we can make them go faster.
Yet this year I’ve been trying to go deeper on "How are actually some of these Ruby C APIs implemented, and what constraints do they put on the VM?". In particular, while Ruby the language has evolved quite a bit from 2.0 (2013) to 4.0 (2025), including several breaking API changes, the C extension API has been extremely stable.
By "extremely stable" I mean — the API has been extensively improved && extended, yet many old C APIs still work as they did back then, and it’s quite likely that any random old Ruby C 15+ year old extension works out-of-the box on the latest Ruby.
In terms of compatibility… this is AMAZING! It means the ecosystem isn’t constantly held back by "very important dependency X or Y has not been updated to latest Ruby".
Yet… there’s a cost. And that cost is performance! The Ruby VM bends over backwards to keep these old APIs working, adding a lot of overhead.
After a bunch of research I thus present to you the Tips for updating Ruby C extensions for efficiently using Ruby 4 VM APIs — my research turned into a tiny doc that now lives as part of the official Ruby documentation.
If you’d like a more "someone hand-waving on stage" version of what I’ve learned about Ruby and C extension APIs, this was the topic of my presentation at RubyKaigi 2026! You’ll find the video and slides below.
Slide deck: