Compacting Heaps in Ruby 2.7
summary
Ruby 2.7 includes a manual heap compactor integrated with the GC and the talk explains exact memory layout, a two‑finger compaction algorithm, pinning bits, compaction callbacks and a rb_gc_location API for extensions. The patch is multi‑year work, initially pins about 3% pinned → 10% smaller heap on a Rails app and later drops to ~1% pinned; object_id shifts to a monotonic object_id. Prototype works but is slow, requires GC.compact today and aims for automatic compaction in Ruby 3.0.
AI-written summary · about
chapters (29)
- 0:00Start
- 3:54Ruby Cores
- 4:22Pipeline Operator
- 4:41Smile Operator
- 9:39Efficient Memory Usage
- 10:35CPU Cache Hits
- 14:18Fragmented Memory
- 16:34Ruby's Heap Layout
- 18:32Moving Objects
- 19:46Updating References
- 20:55Object Movement
- 21:38Reference Updating
- 22:25Finding References
- 24:00Array
- 24:34Hashes
- 27:42Yajl Mark Function
- 28:41Pinning Bits
- 31:47Compaction Callback
- 32:10Problem Object Graph
- 33:35Compilation Process
- 33:53RubyVM Instruction Sequence
- 35:59Problem Code
- 38:18object_id is based on location
- 39:50Object ID Collisions
- 40:12Collision Resolution
- 40:47GC Cleanup
- 43:24Basic Rails Application
- 45:25Sliding Compaction
- 45:45Fixed Width Layout
related talks
51mCompacting GC for MRI
54mKeynote: Exploring Memory in Ruby - Building a Compacting GC
48mDefragging Ruby
51mCompacting GC in MRI
33mThe Bug that Forced Me to Understand Memory Compaction
34mUnder the Hood of Ruby's Generational Garbage Collector
01h 01mKeynote: Mark/Compact GC in MRI
45mClosing Keynote: Analyzing and Reducing Ruby Memory Usage
