InfoQ

News

New Patches for 1.8.x Fix Memory Leaks And Improve Performance

Posted by Werner Schuster on Jan 06, 2009 06:05 PM

Community
Ruby
Topics
Ruby on Rails ,
Performance & Scalability ,
Runtimes
Tags
Rails ,
GarbageCollection

Ruby 1.9.1 and JRuby currently lead the pack of Ruby implementations when it comes to performance. However, for various reasons, switching to either of these Ruby implementations might not be possible just yet, as Ruby 1.9.x breaks compatibility with 1.8.7 in some areas and JRuby still lacks some Ruby libs that use native extensions. With that in mind, MRI 1.8.x seems here to stay for the near future, so there's interest in improving its perfomance.

Brent Roman now brings a few performance improvements to Ruby 1.8.x MRI. He started out trying to fix memory leaks in Ruby, particularly in continuations:

The basic technique is a refinement of the one Kurt Stephens suggested. It not only eliminates the leaks in this one liner:
loop {@x=callcc{|c|c}}
but also in our multi-threaded robotics application. Our Ruby process used to grow to 20+ MB during a day long run. The same run now stays smaller than 10MB.

As it turns out, the leaks are caused by GCC optimizations that interact badly with Ruby's conservative GC:

The garbage collector's leaking memory is not really its own fault. The trouble is that the 'C' machine stack is filled with object references. The main reason for this is that gcc compilers create overly large stack frames and do not initialize many values in them. Certain 'C' constructs used in the Ruby interpreter's core recursive expression evaluator generate especially large, sparse stack frames. The function rb_eval() is the worst offender, creating kilobyte sized stack frames for each invocation of a function that may call itself hundreds of times. This results in stacks that are hundreds of kilobytes, often full of old, dead object references that may never go away.

Brent has provided a few patches (against Ruby 1.8.7-patlevel72 which aim to fix these problems.


Testers report significant speedups with the patches while running real world Rails apps. A few issues were reported as well, so it remains to be seen where this goes.

These patches are another example of the open source (Ruby) community improving MRI. Mod_rails (or REE) is another example, which made MRI's Garbage Collector fork-friendly (see the linked news item for an explanation). 

MRI's performance can also vary significantly depending on how it was compiled.

Are you planning on sticking with Ruby 1.8.x in 2009? If yes, what are the main reasons?

No comments

Watch Thread Reply

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.