Rails boot times suck. Waiting between 5 and 25 seconds to restart a server, run a test or to open the Rails console just doesn’t cut it. When doing TDD, you need the shortest feedback cycle possible.
Performance patched Ruby installs give you a significant improvement, and with Ruby 2.0, the require path is much faster than it used to be. These improvements are great, but we can still do more.
On cue, in comes Zeus. In a nutshell, Zeus preloads your development and test environments and makes the on-demand initialization of Rails servers, tests, rake tasks and consoles blisteringly fast. More technically speaking, Zeus is a process checkpointer for single-threaded applications. It’s been built for Ruby, but support for other languages is planned. For this post however, I just care about Ruby.
Zeus is an external piece of software to your Rails app. It’s distributed as a gem, but must not be included in your Gemfile. It’s designed to be run outside of bundler.
To install Zeus, simply install the gem:
gem install zeus
Once Zeus is installed, cd to your project directory and run:
Zeus then fires up Ruby and checkpoints it at a point where you can connect to the process to run commands such as
To demonstrate, once Zeus has initialised, run
zeus rspec spec and watch the magic happen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
Bind it to a hotkey:
Gotcha with oh-my-zsh
If you’re using the OMZ bundler plugin, you’ll need to remove the
zeus command from the plugin’s autobundle list in
~/.oh-my-zsh/plugins/bundler/bundler.plugin.zsh. Zeus will run your application through bundler by itself. Running Zeus inside bundler slows it down.
I find myself making single line changes and just running my specs habitually now, where I wouldn’t have bothered in the past. The responsiveness and feedback is addictive!