[rspec-users] Using require_relative to speed up rspec require time.

David Chelimsky dchelimsky at gmail.com
Sat Nov 12 17:06:46 EST 2011

On Nov 12, 2011, at 12:58 PM, Ian Leitch wrote:

> Hi,
> I noticed recently that require 'rspec' on my machine was taking close
> to half a second. That's not a huge amount of time, but it is still
> the single slowest part of my test suite.
> It boils down to Ruby 1.9's rather slow require. I'm using 1.9.3, but
> I'd still like to shave off some of the require time.
> As an experiment, I went into rspec-core and rspec-expectations (the
> two biggest offenders) and replaced all require calls with
> require_relative. The benefits are actually quite impressive:
> rspec-core:
> before: 0.16s
> after: 0.10s
> rspec-expectations:
> before: 0.16s
> after: 0.05s
> Applying this to rspec-mocks also, my total require time for 'rspec'
> has gone from 0.5s to 0.21s.
> These are just quick a nasty timings, but there's obviously some win to be had.
> Would David, or the RSpec developers in general accept a patch to use
> require_relative if 1.9 is detected? Are there scenarios under which
> require_relative would not be possible?

I can't think of a reason why this would be problematic, as long as we're not redefining existing methods that other code might be using.

My only concern is the details of the implementation, and I'm not sure what I'd like to see there. Would you please file a pull request with just one of the libs (rspec-core is probably best) and once we get settled on the implementation details we can do it for the others.


More information about the rspec-users mailing list