Understand Why GC in Ruby 2.1 and 2.2 Is So Much Faster
In this book we repeatedly observed that new Ruby versions consistently perform better because the GC is faster. But why is it faster?
The first reason it’s faster is that less GC is needed. We have just seen that with our memory allocation example. The second reason is that each individual GC run can take less time.
Ruby implements GC using a simple two-phase mark and sweep (M&S) algorithm. In the mark phase it finds all living objects on the Ruby heap and marks them as live. In the sweep phase it collects unmarked objects.
Naturally, GC can’t allow you to allocate new objects while it marks. So your program pauses for the duration of GC.
Ruby 2.1 with RGenGC reduces the number ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access