Forum: RSpec Using require_relative to speed up rspec require time.

Posted by Ian Leitch (Guest)
on 2011-11-12 20:03
(Received via mailing list)
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?

Cheers
Ian
Posted by David Chelimsky (Guest)
on 2011-11-12 23:59
(Received via mailing list)
On Nov 12, 2011, at 12:58 PM, Ian Leitch wrote:

> two biggest offenders) and replaced all require calls with
> 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.

Cheers,
David
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.