Speed up your rails startup time

I’ve found when developing that the faster my rails app can start, the faster I can develop. This is mostly because of the speed I can start test cases. But speed of starting a server or a console is also a big factor. I’d like to present a summary of what others have shown to aid in this performance.

Eliminate unnecessary gems

First tip comes courtesy of tenderlove: The number of gems installed on your system can impact rails boot time In short, the gemspecs on your system are all loaded as your app starts () even when using bundler. Some inconsiderate gemspecs can make this even worse by performing I/O as they’re loaded. To remedy this use gemsets if you’re using rvm and eliminate unnecessary gems from your system.

uninstall outdated gems:

gem cleanup

uninstall ALL THE gems:

gem list | cut -d" " -f1 | xargs gem uninstall -aIx


Second, Jesse Storimer recommends running ./script/rails rather than rails itself. For example rails c becomes ./script/rails c. This results in a small but worthwhile performance improvement: ruby and gems are not only loaded once. I’ve created a shell command (tested in bash and zsh) to run script/rails if it exists and rails otherwise (ex. rails new).

function rails {
   if [ -e "script/rails" ]; then
      ruby script/rails $@
      `which rails` $@

Living dangerously

Another posibilty is using one of the patched ruby interpreters. funny-falcon maintains verious performance patches. Patched interpreters are easily installed with rvm.

Upgrade your rails

Finally, upgrade your rails apps to version 3.2 if you haven’t already. Startup time is significantly improved in this version.