Keynote: Exploring Memory in Ruby - Building a Compacting GC
summary
Builds a mark‑and‑compact GC for MRI that exposes GC.compact, implements two‑finger compaction with forwarding T_MOVED entries and a GC_update_references pass, and adds a pin‑bits table to avoid moving RB_GC_marked objects, hash‑keyed objects, C‑extension globals and literals. On a test Rails boot 46% of objects are movable; a synthetic CoW measurement shows ~154 KB PSS savings after compaction. Uses ObjectSpace.dump_all to map object addresses and /proc/<pid>/smaps to measure RSS/PSS; code and tooling live in a GitHub fork for inspection.
AI-written summary · about
chapters (37)
- 0:00Start
- 4:51Exploring Memory in Ruby
- 6:53Ruby String
- 8:11Ruby Array
- 8:21Ruby Hash
- 9:32Ruby Fork
- 10:06OS Memory Copy
- 13:51Mark Phase
- 14:44Bitmap Marking
- 16:45Nakayoshi Fork Source
- 17:24Object Allocation
- 18:21Compact Before Fork
- 21:12Disadvantages
- 22:06Algorithm
- 22:16Object Movement
- 23:56Reference Updating
- 25:48Usage
- 28:00Reference Update Helpers
- 29:15Pure Ruby References
- 30:09C References
- 32:27rb_gc_mark
- 33:17Hashing
- 34:22Dual References
- 36:04Global Variables (in C)
- 37:03String Literals
- 38:01What can move?
- 39:11Before Compaction
- 39:34After Compaction
- 40:15ObjectSpace.dump_all
- 40:55Measuring Rails Boot
- 41:11Output
- 41:56Heap Fragmentation
- 43:43proc/{PID}/smaps
- 44:58RSS vs PSS
- 45:32Copying Memory
- 45:49Shared Dirty, PSS, RSS
- 46:16Compaction Impact







