Ruby garbage collection has always been a frequently discussed topic in the community. With recommendations on tuning strategies for better performanc

New for Ruby 3.4: Modular Garbage Collection and MMTk

submited by
Style Pass
2025-01-09 07:30:03

Ruby garbage collection has always been a frequently discussed topic in the community. With recommendations on tuning strategies for better performance, and even entire sets of patches designed to optimize it, going back at least as far as 2008 and Ruby 1.8.

I spoke at RubyKaigi in 2023 about the history of the Ruby garbage collector, and its evolution since the origins of the language. In that talk I mentioned some of the changes that we were working on at Shopify, to make the Ruby GC easier to modify, and ensure that we’re able to evolve it to more closely follow the cutting edge of memory management research.

For the first time, Ruby will ship with the functionality to safely replace its garbage collector with an alternative implementation at runtime, as well as a completely new implementation that leverages this ability to replace the default Mark & Sweep collector without requiring Ruby to be re-compiled.

I’ll use the rest of this blog post to talk about these new concepts: The way that the Ruby VM now interacts with its various GC libraries, and the new GC implementation itself, which is based around the Memory Management Toolkit (MMTk), a general purpose garbage collection and memory management library.

Leave a Comment