Skip to content

Instantly share code, notes, and snippets.

@burke
Forked from funny-falcon/cumulative_performance.patch
Created January 27, 2012 13:44
Show Gist options
  • Save burke/1688857 to your computer and use it in GitHub Desktop.
Save burke/1688857 to your computer and use it in GitHub Desktop.
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 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/1688857/rbenv.sh | sh ; rbenv global 1.9.3-p327-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.

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-p327" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz" combined_patch
VERSION="1.9.3-p327"
curl https://raw.github.com/gist/1688857/2-$VERSION-patched.sh > /tmp/$VERSION-perf
rbenv install /tmp/$VERSION-perf
@agis
Copy link

agis commented Feb 6, 2013

Mountain Lion+RVM users follow instructions by @cannikin.

@NielsKSchjoedt
Copy link

And if you are getting Error running 'make ' you might have to append --with-gcc=gcc so the line looks like: ``rvm install 1.9.3-p327 -n fast --patch falcon --with-gcc=gcc`

@krohrbaugh
Copy link

ruby-build has S3-based mirrors for the various dependencies, which you can make use of in this gist, for times when sites like pyyaml.org go down.

To do so, change line 14 and 15 of 2-1.9.3-p327-patched.sh to be:

install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz#36c852831d02cf90508c29852361d01b"
install_package "ruby-1.9.3-p327" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz#96118e856b502b5d7b3a4398e6c6e98c" combined_patch

(I'm simply pulling these out of ruby-build's relevant manifest files here.)

That will attempt to download from the source and then fall-back to the S3 mirror if needed.

@umtrey
Copy link

umtrey commented Nov 21, 2013

This hasn't been touched in a while, but with the new gist links, things will likely break. I've made a version of the rbenv definition file that should work, for the time being.
https://gist.github.com/umtrey/7592062

@m-shirshendu
Copy link

To get rid of the following error:

regparse.c:582:15: error: implicit conversion loses integer precision: 'st_index_t' (aka 'unsigned long') to 'int' [-Werror,-Wshorten-64-to-32]

In addition to https://gist.github.com/umtrey/7592062, I had to do the following first

brew update
brew tap homebrew/dupes
brew install apple-gcc42
export CC=gcc-4.2

Then rbenv install /tmp/1.9.3-p327-perf

@chuckbergeron
Copy link

Thanks @m-shirshendu! That did the trick.

@agis
Copy link

agis commented Jul 9, 2014

Trying to install with ruby-install I got the following error (Using GCC 4.2):

....
compiling proc.c
compiling file.c
make: *** No rule to make target `pool_alloc.inc.h', needed by `gc.o'.  Stop.
!!! Compiling ruby 1.9.3-p327 failed!

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