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

Optimize Base#relevant_rubocop_rspec_file? #967

Closed
wants to merge 1 commit into from

Conversation

bquorning
Copy link
Collaborator

@bquorning bquorning commented Jul 15, 2020

Another take on #965.

The result of rspec_pattern is always the same (because it is based on the configuration file), so there is no need to re-calculate it every time it is called.

I tried memozing on the Cop Base instance, but at least when running the specs, we instantiate Cop Base way too often. Memoizing on the class level reduces the number of calculations to once per Base subclass we have. If we allowed using class variables (@@rspec_pattern) we could reduce the number of calculations to one.

This commit reverts 995b4fe and adds memoization in a class instance variable.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • [-] Added tests.
  • [-] Updated documentation.
  • [-] Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

@bquorning bquorning requested a review from marcandre July 15, 2020 09:53
@bquorning bquorning marked this pull request as ready for review July 15, 2020 09:53
@bquorning
Copy link
Collaborator Author

And of course this doesn‘t work with specs (spec/rubocop/cop/rspec/cop_spec.rb) that change the configuration.

Config.new
.for_all_cops
.fetch('RSpec', default_configuration)
.fetch('Patterns')
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the configuration merged with the default configuration, can we assume that AllCops/RSpec/Patterns is always present?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. We can just use ConfigLoader.default_configuration.for_all_cops here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Still, I’m struggling to figure out how to make this work with the changing configurations in cop_spec.rb

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, but… I tried, and I cannot make it work.

Would you like to give it a shot @pirj – you’re welcome to add a commit to my branch. (I’ve just rebased it, so make sure to re-fetch first).

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather wait for #956 to be merged, it shuffles some methods between Base and RSpecConfig, and this is actually what #1007 is based upon (unless it also felt slightly behind).
Or did you plan to merge this prior to 2.0?

Copy link
Collaborator Author

@bquorning bquorning Aug 23, 2020

Choose a reason for hiding this comment

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

Yeah, I hoped this was a small enough change that we could merge it pre-2.0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But of course, if testing makes it a post-2.0 we can wait.

Copy link
Member

Choose a reason for hiding this comment

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

I mean it could be part of 2.0, not even post-2.0. We have a bunch of pull requests specifically for 2.0.

The result of `rspec_pattern` is always the same (because it is based
on the configuration file), so there is no need to re-calculate it every
time it is called.

I tried memozing on the Cop instance, but at least when running the
specs, we instantiate Cop way too often. Memoizing on the class level
reduces the number of calculations to once per `Cop` subclass we have.
If we allowed using class variables (`@@rspec_pattern`) we could reduce
the number of calculations to one.

This commit reverts 995b4fe and adds
memoization in a class instance variable.
@bquorning bquorning changed the title Optimize Cop#relevant_rubocop_rspec_file? Optimize Base#relevant_rubocop_rspec_file? Aug 22, 2020
@pirj pirj added this to the 2.0 milestone Aug 25, 2020
@bquorning bquorning mentioned this pull request Sep 5, 2020
16 tasks
@bquorning bquorning changed the base branch from master to release-2.0 October 21, 2020 20:49
@bquorning bquorning mentioned this pull request Oct 22, 2020
@pirj pirj mentioned this pull request Oct 27, 2020
9 tasks
@bquorning
Copy link
Collaborator Author

Fixed in #1063.

@bquorning bquorning closed this Oct 29, 2020
@bquorning bquorning deleted the rspec_pattern branch October 29, 2020 12:09
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