Skip to content

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

Merged
merged 7 commits into from Feb 25, 2014

3 participants

@myronmarston
RSpec member

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

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

@myronmarston myronmarston referenced this pull request in rspec/rspec-expectations Feb 23, 2014
Closed

[DO NOT MERGE] Use require relative to load files. #476

@myronmarston
RSpec member

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

@soulcutter soulcutter commented on the diff Feb 24, 2014
lib/rspec/core.rb
-require_rspec['core/world']
-require_rspec['core/configuration']
-require_rspec['core/option_parser']
-require_rspec['core/configuration_options']
-require_rspec['core/command_line']
-require_rspec['core/runner']
-require_rspec['core/example']
-require_rspec['core/shared_example_group/collection']
-require_rspec['core/shared_example_group']
-require_rspec['core/example_group']
+require "rspec/support"
+RSpec::Support.require_rspec_support "caller_filter"
+
+RSpec::Support.define_optimized_require_for_rspec(:core) { |f| require_relative f }
+
+%w[
@soulcutter
RSpec member
soulcutter added a note Feb 24, 2014

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

@JonRowe
RSpec member
JonRowe added a note Feb 24, 2014

Ya, think I agree...

@myronmarston
RSpec member
myronmarston added a note Feb 24, 2014

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)?

@soulcutter
RSpec member
soulcutter added a note Feb 25, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
myronmarston added some commits Feb 24, 2014
@myronmarston myronmarston One line per require file. b088f95
@myronmarston myronmarston Remove benchmark file.
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]
6c4ecea
@myronmarston
RSpec member

Any other concerns before I merge this?

@JonRowe JonRowe commented on the diff Feb 25, 2014
lib/rspec/core/configuration_options.rb
@@ -1,5 +1,6 @@
require 'erb'
require 'shellwords'
+require 'set'
@JonRowe
RSpec member
JonRowe added a note Feb 25, 2014

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

@myronmarston
RSpec member
myronmarston added a note Feb 25, 2014

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@JonRowe
RSpec member
JonRowe commented Feb 25, 2014

Did you update the benchmarks for the current script?

@myronmarston
RSpec member

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
RSpec 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
RSpec member

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 myronmarston merged commit 1e5ea31 into master Feb 25, 2014
@myronmarston myronmarston deleted the benchmark-require-relative branch Feb 25, 2014
@bf4 bf4 referenced this pull request in rails-api/active_model_serializers Sep 17, 2015
Merged

add require statements to top of file #1171

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.