How I decreased my Rails startup time by 60%

Today I decreased my Ruby On Rails boot time by ~60%, Yay!
(All credit goes to funny-falcon for the patches and Burke who posted the Gist)

I removed 26 gems from my Gemfile and I noticed a boost with a couple of seconds. From that I begun searching for large Gemfile problems and I stumbled on this gist https://gist.github.com/1688857

It a pretty long page, so I will just summarize how I got my 60%

I use ruby 1.9.3-p125 and rbenv and ruby-build for handling ruby.

First we need to create a manifest file for our new patched ruby

Create a file named ruby-1.9.3-perf with the following content

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
build_package_combined_patch() {
  local package_name="$1"
  {
    curl 'https://raw.github.com/gist/1859082/performance_and_backport_gc.patch' | patch -p1
    autoconf
    ./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
    make -j 8
    make install
  } >&4 2>&1
}

require_gcc

install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.3-p125" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz" combined_patch

When we have our manifest file in place we can use ruby-build to build ruby

1
ruby-build ./ruby-1.9.3-perf ~/.rbenv/versions/ruby-1.9.3-p125

And here is my final results!

1
2
3
4
5
6
7
8
9
10
11
12
13
Before

time -p bundle exec rake environment
  real 6.81
  user 5.93
  sys 0.85

After

time -p bundle exec rake environment
  real 3.75
  user 2.82
  sys 0.91

All credit goes to funny-falcon for the patches and Burke who posted the Gist.

Posted in Rails, Ruby at February 29th, 2012. Trackback URI: trackback Tags: , , , Written by: 
  • Pablo

    Anyone knows if any of these patch will eventually be included in MRI?

  • Mathias Stjernstr√∂m

    funny-falcon writes in the Gist comments that ruby 1.9.3 will not add any “new features”, but I guess they will be added in a future release.

    Link to his comment

  • http://twitter.com/mcmire Elliot Winkler

    First of all: Good. Grief. I can definitely tell the difference right away. Timed various tasks and I also have about a 50-60% performance increase. Amazing stuff for sure.

    Two things. One: To install ruby-build, you can either follow the instructions on github, or `brew install ruby-build`.

    Two: it’s more consistent with your other Ruby versions if you leave out the “ruby-” in the name. I’d also give it a suffix too — if you already have 1.9.3-p125 installed, probably not a good idea to override it in case you hose yourself. So:
    ruby-build ./ruby-1.9.3-perf ~/.rbenv/versions/1.9.3-p125-falcon

    But anyway, thanks for the rbenv instructions.

It's past my bedtime is using WP-Gravatar