Must Read Rails Performance Article
Posted by Charlie Sat, 02 Feb 2008 22:58:00 GMT
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.

I assume multiple “excepted”s should be “accepted”s.
Bob,
Yes, good catch. Thanks and fixed.
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.
Hi Aristus,
The problem is in line 28 of measure_memory.h:
if defined(HAVERB_GCALLOCATED_SIZE)
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.
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_SIZEthing.If that doesn’t happen, you can fetch ruby-prof sources from svn trunk and do
or something like this.
See my memory profiling article for more details: http://blog.pluron.com/2008/02/memory-profilin.html