Skip to content

Instantly share code, notes, and snippets.

@davidcelis
Forked from burke/0-readme.md
Last active October 17, 2016 11:28
Show Gist options
  • Save davidcelis/4381019 to your computer and use it in GitHub Desktop.
Save davidcelis/4381019 to your computer and use it in GitHub Desktop.
Ruby 1.9.3-p362 cumulative performance patch for rbenv

NOTE: THIS PATCH DOES NOT APPLY. Falcon's performance patches have not been updated for p362. See the comments for a fork that uses the Rails Express patch set instead.

ruby-1.9.3-p362 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p362 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

Ok, let's do this!

curl https://raw.github.com/gist/4381019/rbenv.sh | sh ; rbenv global 1.9.3-p362-perf

BONUS!

Putting the following in your shell config (eg. ~/.bash_profile) will make Rails even faster, but will increase its memory footprint. For most applications, this will probably work well for you:

export RUBY_GC_MALLOC_LIMIT=60000000
export RUBY_FREE_MIN=200000

If you have a particularly large rails app (say, >100k lines), this seems to improve it even more:

export RUBY_GC_MALLOC_LIMIT=1000000000
export RUBY_FREE_MIN=500000
export RUBY_HEAP_MIN_SLOTS=40000

More BONUS!

If you're feeling adventurous, you can set some additional compile flags before you run the command above. These may cause the build to fail. If so, you can try again without the march flag, and it'll probably work. This generally makes my ruby ~1.5% faster. See http://en.gentoo-wiki.com/wiki/Safe_Cflags/Intel for more guidance. I had to change it to -march=core2 on my Macbook Air 2011/11".

export CFLAGS="-march=native -O3 -pipe -fomit-frame-pointer"

This has to be run BEFORE you compile ruby.

Even MORE BONUS!

Users who have installed libreadline and openssl via homebrew will find these libraries linked automatically. No need to specify any CONFIGURE_OPTS!

build_package_combined_patch() {
local package_name="$1"
{
curl https://raw.github.com/gist/4136373/falcon-gc.diff | patch -p1
autoconf
./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 8
make install
} >&4 2>&1
}
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.3-p362" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p362.tar.gz" combined_patch
VERSION="1.9.3-p362"
curl https://raw.github.com/gist/4381019/2-$VERSION-patched.sh > /tmp/$VERSION-perf
if command -v brew > /dev/null
then
if brew --prefix openssl > /dev/null
then
CONFIGURE_OPTS="$CONFIGURE_OPTS --with-openssl-dir=`brew --prefix openssl`"
fi
if brew --prefix readline > /dev/null
then
CONFIGURE_OPTS="$CONFIGURE_OPTS --with-readline-dir=`brew --prefix readline`"
fi
fi
rbenv install /tmp/$VERSION-perf
@aaronchi
Copy link

It would be relevant if it worked!

@BugRoger
Copy link

@davidcelis
Copy link
Author

Whoops, I had no idea this had become the top google result. Sorry!

@7hunderbird
Copy link

I updated this to p374 for railsexpress because p362 has been reported as segfaulting on many rails apps: https://gist.github.com/4637375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment