Performance Plus Oil

Performance Plus Oil

Commercial Contractors

Commercial Contractors

Marushka Handprints

Marushka Handprints

CDCookie

CDCookie

Wheatley-Gaso

Wheatley-Gaso

D.R. Gillcrest

D.R. Gillcrest

Installing a patched Ruby 1.9.2 for faster Rails startup

Created 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!

  1. Priti Priti — April 20, 2012

    rails s/usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require’: no such file to load openssl (LoadError)from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require’from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency’from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:591:in `new_constants_in’from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:225:in `load_dependency’from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.1/lib/active_support/dependencies.rb:239:in `require’…..my rails esovirn is 3.0.1. and i am not using rvm. Could you tell me how can i get rid of this error.

What are your thoughts?