I’ve been in a number of rails projects, but the one I’m currently handling right now has about 200+ models — the biggest rails project I’ve seen so far.
I’ve been thinking of ways to make our rails app boot faster our daily work more productive. If you’re debugging and/or running unit tests iteratively, it can be a huge pain in the ass to load the whole development environment every single time! In fact, I’d go as far as saying slower tests will demotivate programmers and it will encourage less test runs.
Yes, you can tinker your code or your test setup (e.g. see which dependencies in your Gemfile you can require at a later time) but that should be your last step. Consider first the tasks that will yield the most results with least amount of effort.
Here are the top 2 tips that will decrease your waiting time by more than 50% but will only take up to 15 minutes:
Install a rails preloader gem e.g. Zeus
While this tip doesn’t really optimize your rails boot time per se, it saves you from waiting to load your test/development environment by loading it before you need it. This is why Zeus can claim:
Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second.
You can quickly try this out with the following:
Aside from Zeus, you can also try out Spring
Install railsexpress ruby patch
- get the latest rvm
- install railsexpress patch to your current ruby
- Benchmark to see how far you’ve improved the boot time by just applying this patch. Here’s the result on my machine:
More than 50% of the original boot time is shaved off by just applying the patch! I know 1 minute is pretty slow, but to bring it down into less than 30 seconds with a simple task is a big win!
For more information, check out the rvm patchsets repository.