Must Read Rails Performance Article

A couple of days ago, Alex Dymo from Pluron sent me an email describing some of the great work he has done optimizing the performance of their online project managment software Accunote. His great insight was that their performance problems were caused by allocating too much memory, thus forcing Ruby’s Garbage Collector to frequently run ruining performance.

Using a patched version of ruby and ruby-prof, Alex was able to more than double performance (with hints of more to come) and reduced memory consumption by 75%, or 750MB (yes – that is Megabytes). Alex does a wonderful job of documenting his approach with a series of blog posts here and here.

The main culprit was Rail’s handling of attributes, which is dreadfully designed (an obvious case of the simplest solution to a problem is the wrong solution – something I’ve been meaning to blog about for almost a year now ). But he also implicated Ruby’s built-in benchmarking module.

Even better, Alex provided patches to ruby core (already accepted), Rails (already accepted) and ruby-prof. We’ll also gladly accept his patches, and since its about time for a ruby-prof refresh, we’ll spin out a new release as soon as we can. More to follow.

  1. Bob
    February 3, 2008

    I assume multiple “excepted”s should be “accepted”s.

  2. Charlie Savage –
    February 3, 2008


    Yes, good catch. Thanks and fixed.

  3. Aristus
    February 4, 2008

    Any tips on how to install/compile these patches? I’ve patched the ruby binary and installed ruby-prof-0.6.0 from gem, but RubyProf::MEMORY still evaluates to nil.

  4. Charlie
    February 5, 2008

    Hi Aristus,

    The problem is in line 28 of measure_memory.h:


    But that constant is not defined in Alex’s patch.

    So just uncomment out that #if and it should hopefully work. And I’ll ask Alex about it.

  5. Alexander Dymo
    February 10, 2008

    Aristus, to have memory profiler you need to install patched ruby, then make sure the patched ruby interpreter is in the path and build ruby-prof gem.

    extconf.rb in the gem should take care of defining `HAVE_RB_GC_ALLOCATED_SIZE` thing.

    If that doesn’t happen, you can fetch ruby-prof sources from svn trunk and do

        cd ext
        ruby extconf.rb
        cd ..
        rake gem
        cd pkg
        gem install ruby-prof-0.6.0.gem

    or something like this.

    See my memory profiling article for more details: