Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmark require relative and update to new rspec-support method #1348

Merged
merged 7 commits into from Feb 25, 2014

Conversation

myronmarston
Copy link
Member

Some benchmarks for discussion with rspec/rspec-expectations#476.

I'll leave some comments there about what this means, I think.

@myronmarston
Copy link
Member Author

This has been updated to leverage the rspec support method from rspec/rspec-support#45. It'll fail until that's merged.


RSpec::Support.define_optimized_require_for_rspec(:core) { |f| require_relative f }

%w[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sorta miss the line-per-require format - it allowed for groupings and it was easier to read even though it was repetitive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, think I agree...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially had that, but we had more duplicated on each line (the RSpec::Support.require_rspec_core bit) than was different on each line (the file name). So I collapsed it.

What do you think about keeping the array.each but putting each file on its own line (with optional blank lines in there for grouping)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds fair to me.

The require method could also take varargs so that RSpec::Support.require_rspec_core is up-front instead of trailing the array… but I don't have strong feelings about that TBH.

This benchmark suggested that `require_relative` isn't
any faster than `require`, because it put `rspec/core/lib`
onto the load path as the first dir, which made `require`
for rspec-core files O(1) like `require_relative`.

In practice, people's load path will have many more directories
and this benchmark doesn't align with that reality.

[ci skip]
@myronmarston
Copy link
Member Author

Any other concerns before I merge this?

@@ -1,5 +1,6 @@
require 'erb'
require 'shellwords'
require 'set'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An aside, are we not worried about polluting stdlib here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a new require; see 322d272.

We prefer not to pollute stdlib, but it's not an absolute rule.

@JonRowe
Copy link
Member

JonRowe commented Feb 25, 2014

Did you update the benchmarks for the current script?

@myronmarston
Copy link
Member Author

Did you update the benchmarks for the current script?

Nope. Not sure what you have in mind for updating it. The results? It's also kinda annoying to re-run it as to compare relative vs non-relative require you have to edit rspec-support (since it always uses relative when available). We're satisfied that the benchmarks demonstrate that require_relative is never slower than require and is faster when $LOAD_PATH is large....so what would be the benefit of updating the benchmarks at this point?

@JonRowe
Copy link
Member

JonRowe commented Feb 25, 2014

To prove they have same performance benefit as the raw require_relative, or just remove them as stale already :)

@myronmarston
Copy link
Member Author

To prove they have same performance benefit as the raw require_relative, or just remove them as stale already :)

I re-ran the benchmarks, and am getting very similar numbers. I'm not going to update them since that'll just create unnecessary git history churn.

myronmarston added a commit that referenced this pull request Feb 25, 2014
Benchmark require relative and update to new rspec-support method
@myronmarston myronmarston merged commit 1e5ea31 into master Feb 25, 2014
@myronmarston myronmarston deleted the benchmark-require-relative branch February 25, 2014 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants