Down the rb_newobj() Rabbit Hole: Garbage Collection in Ruby
summary
Shows that New Relic’s move to Ruby 1.9.3 cuts Ruby GC wall time (roughly 80 ms to 42 ms in one example) by changes under the hood, not by higher‑level patterns. Walks C code from rb_newobj() through class allocators, macros such as the RSTRING_PTR macro, embedded short‑string storage, heaps and free lists, and explains why classic mark‑and‑sweep and Ruby 1.9’s lazy sweep cost time. Demonstrates bitmap marking to enable shared memory / copy‑on‑write and why that reduces pauses.
AI-written summary · about
chapters (26)
- 0:00Start
- 5:56What is GC? Garbage collector's function is to find data object that are no longer in use and make their space available for reuse by the running program
- 6:20ObjectSpace A module for interacting with garbage collection and traversing all living objects.
- 7:39Create a Class
- 8:35Empty the Array
- 9:03Remove the Class
- 10:29VALUE and Objects VALUE, an unsigned long, is a pointer to Ruby's objects.
- 12:20RBasic and RObject struct Basic
- 13:39RObject Structure
- 14:17Ruby and Macros Understanding C macros is essential to understanding Ruby source.
- 14:51RString Magic struct Basic basic
- 16:17RString Macros
- 18:41Ruby Heaps
- 21:50Define Alloc Method
- 23:32Create Ruby Object VALUE
- 24:59Get the Next Free Slot
- 25:32Return the Object
- 28:10Create Objects
- 28:21Object Allocation Heap
- 29:15Object Anatomy
- 30:32Sweep Phase Traverse every object in the object space. Those with a mark are unmarked. Those that are already unmarked are added to the free set.
- 32:50Copy-on-Write When a process is forked, memory is shared. Memory is copied only when it is changed. Marking an object is considered changing it.
- 33:56COW Anatomy Shared Heap Heap B
- 34:33Bitmap Marking Ruby 2.0 introduces a new type of garbage collection. FL_MARK flag has been moved to a bitmap memory structure.
- 35:01New Heap Anatomy
- 35:45Learn More Uniprocessor GC Techniques, Paul Wilson
related talks
49mRabbit Hole: Garbage Collection and Ruby's Future
34mUnder the Hood of Ruby's Generational Garbage Collector
53mRuby.inspect
21mUnderstanding Garbage Collection in Ruby
55mComplex Ruby concepts dummified
38mWhy I am excited about Ruby 2.1?
42mTweaking Ruby GC Parameters for Fun, Speed, and Profit
35mThe Hitchhiker's Guide to Ruby GC
