Spork is a forking test runner for RSpec and Cucumber that allows you to run your tests almost instantaneously, without waiting for the entire Rails stack to load. If you haven’t checked it out, I strongly recommend you do so now (use 0.9.0.rc4 for Rails 3 support) – it’s awesome for iterative/test-first development.
For those who are using Spork already, here are two tricks to squeeze out the last few deciseconds from the start-up time:
Avoiding bundle exec
It’s much faster to run rspec --drb
than bundle exec rspec
--drb
. Using bundle exec
imposes a performance penalty of more
than 1.5 seconds on my system. Just make sure that the rspec
or
cucumber
binary on your system and the gem listed in your
Gemfile.lock
are the same version – then there should not be any need
for bundle exec
.
Profiling require
You can also add extra require
statements to your
Spork.preload
block to force preloading. Here is a quick and dirty
hack to find files that should be loaded at preload
time:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Now restart spork, and run rspec --drb
or cucumber --drb
. It
will print a bunch of modules that have been required after forking, prefixed
by milliseconds. Indentation indicates indirect requires – read the list from
bottom to top. The output should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
I suggest preloading any modules at the left-most indentation level that (a) do
not belong to your project and (b) take more than 100 milliseconds. In my
case, I’ve added the following block to my preload
block:
1 2 3 4 5 6 7 8 9 |
|
Restart spork, and check that there are no left-over slow-loading modules. Then remove the tracing code. :-)
It’s a hack and only shaves off another 1.5 seconds on my system, but I think it’s worth it for something that I run hundreds of times a day.