Compacting GC for MRI
summary
Compacting GC for MRI ships with Ruby 2.7 and takes three years of development; it implements a two-finger compaction over Ruby’s 40-byte slot, 16KB page heap, moving objects then updating references (reference-updating is ~80% of the patch). It adds pinning bits and compaction callbacks so C extensions don’t break, maintains object_id via a seen-ID map, cuts fragmentation to reclaim measurable Rails heap space, and currently runs as a 4-step GC that the team plans to shrink to 2–3 steps.
AI-written summary · about
chapters (11)
- 0:00Introduction and personal anecdotes
- 13:12What is compaction
- 22:27Ruby’s heap structure
- 23:52Two-finger compaction algorithm
- 27:53Updating references complexity
- 29:00Supporting C extensions
- 37:00Hidden references problem
- 41:57Marking references rule
- 42:17Object ID challenges
- 46:33Impact on memory usage
- 48:17Future improvements







