Ruby 2.1.0 Released, Delivering new GC
The official release of Ruby 2.1 has arrived, bringing with it a number of anticipated improvements, including big changes to the garbage collector which will bring several performance enhancements now and in the future.
The garbage collector in Ruby 2.1 implements a form of generational garbage collection, with Ruby calling their implementation RGenGC (Restricted Generational Garbage Collection). This replaces the “Mark & Sweep” implementation used in previous versions of Ruby. A presentation by Ruby developer Koichi Sasada in April 2013 observed that the challenge for Ruby developers was to implement a GC algorithm that could handle both protected and unsafe objects in the same heap.
Since rewriting all existing C-extensions to use the new GC is not practical, Write-Barriers are used as part of the RGenGC implementation. As Sasada explains in a presentation (PDF) given at RubyConf 2013, RGenGC provides a third way given the 2 original alternatives: A) Do not implement generational GC at all (as in Ruby 2.0 & before) or B) Implement Generational GC with a requirement that all C-extensions are rewritten.
Using RGenGC provides high compatibility with existing extensions while still bringing performance improvements. Popular objects Array, String, Hash, Object, and Numeric are Write-Barrier protected, thus able to take advantage of the RGenGC system. Future work on both internal and external libraries offer the possibility of additional performance gains in the future.
The new garbage collection system is not the only improvement, others include RDoc 4.1.0, RubyGems 2.2.0, and several updated libraries. For a complete list of 2.1’s changes take a look at the release notes located at the project’s GitHub page.
John Altidor, Yannis Smaragdakis Mar 30, 2015