Ruby Performance Roundup: GC Tuning, MagLev, MacRuby
The Garbage Collector in Ruby 1.8 has received a lot of attention in the past year. The developers behind Ruby Enterprise Edition (REE), have hacked the GC to share memory across processes (details in InfoQ's interview with the creators). REE has become a popular way to deploy and run Rails applications, with 37Signals and many others using it.
Recently the GC in REE was improved with a few bug fixes that removed sporadic freezes.
Users of a standard Ruby 1.8.x can also soon get some improvements from the MBARI patches that fix many GC problems and related memory leaks, and are now sponsored by EngineYard.
Evan Weaver gives GC tuning tips and recommends some patches that allow to monitor the GC. The results of the presented tuning:
Now the GC runs only every 13 requests, at a slightly higher cost, for a per-request cost of 0.009 seconds. This translates to a general speedup of 34%. The frequency of GC calls corresponds quite directly to the change in RUBY_GC_MALLOC_LIMIT, but if we increase it much more the memory usage balloons.
Another way to get more performance is to look at other Ruby implementations, such as JRuby which profits from the maturity of GCs in modern JVMs. Other implementations are aiming to improve the state of the art as well. Rubinius is improving steadily, and MacRuby has recently made news with its experimental branch which showed performance improvements. The work on the experimental branch is progressing:
- The compiler is now able (AFAIK) to compile all the language specs, so I guess it's now roughly complete.[..]
- Thanks to everything above, IRB is now running!
- Tail-call elimination was introduced. This optimization transforms recursive calls into local loops, in order to prevent stack overflows. [..]
- The LLVM IR interpreter was investigated in order to interpret faster #eval expressions. The result of this investigation has been committed and works pretty well with simple expressions, however it is not activated by default yet because of limitations when it comes to call the VM primitives. We will have to modify the LLVM interpreter a little bit in order to fully use it from MacRuby. This will be done in the near future.
Finally, GemStone's Ruby implementation MagLev is now in a private Alpha test, with a Beta coming in Q2. Now, compatibility (RubySpec) and benchmarking results are available at the MagLev website. Updates of the projects are also available on Twitter.
Stuart Williams Aug 02, 2015
David Beyer, Olaf Carlson-Wee, Richard Minerich Aug 02, 2015