In this nice blog post by Justin Kulesza, the author points out that ruby interpreter is compiled by RVM wthout any optimizations at all, and he suggests to add -O3 to CFLAGS. Without a doubt, this adds some performance boost to your ruby interpreter.
But, there are other tricks which you can use to improve the ruby performance.
Note: you need to recompile ruby if you add one of these “tweaks”
Processor-specific CFLAGS
Gentoo Wiki has a section about safe performance flags for your processor. I, for example have a Core Duo CPU, and the Intel section of cflags article says I need to use the following cflags:
CFLAGS="-march=core2 -O2 -pipe -fomit-frame-pointer"
Obviusly, I need to put these values where RVM will recognize them, so .rvmrc in my home directory should look like this:
rvm_configure_env=(CFLAGS="-march=core2 -O2 -pipe -fomit-frame-pointer")
Note: THESE COMPILER FLAGS ARE SAFE FOR MY PROCESSOR ONLY, YOU SHOULD FIND YOURS ON THE WIKI
Edit: as Maxime pointed out, GCC >= v4.3 can autodetect processor features, all you have to do is to pass -march=native as a parameter to the compiler. So .rvmrc should look like:
rvm_configure_env=(CFLAGS="-march=native -O2")
Falcon patch
There is a gist on github, which addresses some of the performance issues ruby 1.9.3 has, and people are reporting up to 2X boost in some scenarios.
Latest versions of RVM knows about this patch, and all you have to do is to specify a flag to rvm when installing ruby:
rvm install 1.9.3-turbo --patch falcon
Falcon patch for p327 is available here.
Result
Unfortunately, I do not have time to do some detailed tests, but here is a small benchmark result (which is not a very good indicator of performance difference).
The test:
time bundle exec rake routes in a big Rails project
(which is in fact the only scenario I wished would be faster in my daily dev life)
ruby 1.9.3 – 30.57s
ruby 1.9.3 -O2 – 23.68s
ruby 1.9.3 -O2 +custom cflags – 23.03s
ruby 1.9.3 -O2 +custom cflags +falcon patch – 6.99s
ruby 1.9.3 -O3 +march=native,O3 +falcon patch – 6.88s
ruby 1.9.3p327 -O3 march=native +falcon patch327 – 8.97s