Marushka Handprints

Marushka Handprints

CDCookie

CDCookie

Wheatley-Gaso

Wheatley-Gaso

Community Home Sales

Community Home Sales

Friday Addition

Friday Addition

Daylily Floral

Daylily Floral

Installing a patched Ruby 1.9.2 for faster Rails startup

Updated by Brian Hempel on January 6, 2012

When you call require, Ruby 1.9.2 uses an O(n^2) algorithm to check if the requested file has already been loaded or not. For large Rails applications, this require time is responsible for most of the startup wait. That’s bad.

Xavier Shay changed the require algorithm in 1.9.3 with impressive performance improvements, his Rails app startup went from 20s to 10s. For those of us still on 1.9.2, Adam Palmblad back-ported the patch to 1.9.2-p180, and it’s since been adapted for p290 as well. We’ll be using the p290 version from Stefan Kaes’ rvm-patchsets repository.

To install a patched 1.9.2 with RVM, paste the following into your terminal:

curl https://raw.github.com/skaes/rvm-patchsets/671f0e4e6487af7a252d86b59d645ee7beb849dd/patches/ruby/1.9.2/p290/railsexpress/05-load-performance-fix.patch > 1.9.2-p290_require_speedup.patch

rvm install 1.9.2-p290 --patch 1.9.2-p290_require_speedup.patch -n patched

rvm alias create 1.9.2-patched ruby-1.9.2-p290-patched

The above is also available as a gist. For one-line install:

bash < <(curl -s https://raw.github.com/gist/1571200/1c05c824ce26d6811592271314323e1a9099924f/1.9.2-p290_require_speedup_easy_install.sh)

Now, a version of 1.9.2 with faster loading is available to you with rvm 1.9.2-patched. With the patch, the startup time for an app I’m working on went from 30s to 15s. Enjoy a faster development cycle!

What are your thoughts?