Automatic GC Compaction in MRI
summary
Automatic compaction becomes a concurrent step that runs with sweeping, implemented with a mprotect read barrier that moves objects back when protected pages are touched. Heap pages expand to exactly 16 KB pages (adding one 40‑byte slot) so pages are mprotect-able. Batching moves at page boundaries reduces calls to mprotect to about 2 calls per ~200 moved objects versus two calls per object, recovering performance after an initial implementation that was ~4.5× slower. Tools: rdoc benchmark (50 runs) and Instruments profiler; feature is functional but auto compaction is off by default because it increases major GC time.
AI-written summary · about
chapters (25)
- 0:00Intro
- 2:05Heap Compaction In a Rails app
- 2:24Heap Before Compaction
- 3:21Compaction Process
- 5:50Compaction Goals
- 6:33Heap Comparison Before and After Compaction
- 8:01Empty Destination Required! Movement
- 10:49Sweep Process After Marking
- 12:33Sweep + Update References Sweep is Paused
- 13:02Sweep Continues Finish up!
- 13:56Ruby Class Hierarchy
- 14:47Sweep Process Sweeping Classes
- 15:15Sweep + Move Process After Marking
- 15:53Crash Backtrace
- 19:02mprotect() requirements
- 20:46Memory Usage Over Time jemalloc
- 21:05Old Size vs New Size
- 22:15Page Widen Diff
- 22:39Compact + Read Barrier
- 23:24Using Instruments
- 23:53Bottleneck: mprotect
- 27:25Comparing to Master
- 28:35Automatic Compaction in Action
- 29:07Auto Compaction Control
- 31:08Major GC: Objects Per Second (higher is better)







