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

Allow cops to restrict callbacks on_send to specific method names only #8365

Merged
merged 2 commits into from Aug 27, 2020

Conversation

marcandre
Copy link
Contributor

@marcandre marcandre commented Jul 19, 2020

Many of the recent optimizations for Cops seem to be to modify on_send to check early for the node.method_name against a specific list of names.

This PR makes this pattern builtin so it is easy to do (just define RESTRICT_ON_SEND = %i[foo bar baz]) and makes it even more efficient.

Let's imagine 100 cops defining on_send that could have such a restricted method list. On a run over 10k SendNode, if these cops are optimized with the first thing in on_send being return if SOME_LIST.include?(node.method_name), there would still be 100*10k calls to on_send, and 100*10k calls to Set#include? (assuming that SOME_LIST is a Set, as it should). With this PR, if the Cops are optimized with the right constant, then there would be only 10k hash lookups.

cc/ @fatkodima

@marcandre
Copy link
Contributor Author

ping @bbatsov

@marcandre
Copy link
Contributor Author

ping @bbatsov Let me know if my ping frequency is too high too 😅

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 5, 2020

The frequency is fine, but I couldn't catch up with all the open PRs. I like the proposed change, but I think we need to document it better if we expect someone to actually use it.

@marcandre
Copy link
Contributor Author

Cool. I'll document this and then merge. Thanks!

@marcandre marcandre force-pushed the less_on_send branch 4 times, most recently from 14ea0c1 to dd2574f Compare August 11, 2020 05:39
@marcandre marcandre force-pushed the less_on_send branch 3 times, most recently from 0968c72 to c703039 Compare August 26, 2020 17:55
@tas50
Copy link
Contributor

tas50 commented Sep 2, 2020

@marcandre I reworked the 200+ cops in Cookstyle to use this new functionality where we could. Since we're autocorrecting a DSL there's a lot of times we're just looking for a deprecated method call that needs to be replaced with a new one. Lots and lots of simple on_sends. My testing shows this sped things up about 16% against a large set of cookbooks. Nice work.

@marcandre
Copy link
Contributor Author

16% is awesome, especially given the minimal trouble it is to specify it! 🎉
Thank @fatkodima who started using this technique manually 😄

koic added a commit to koic/rubocop-performance that referenced this pull request Oct 11, 2020
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
koic added a commit to koic/rubocop-performance that referenced this pull request Oct 12, 2020
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
koic added a commit to koic/rubocop-rails that referenced this pull request Nov 10, 2020
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
koic added a commit to koic/rubocop-rails that referenced this pull request Nov 10, 2020
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
koic added a commit to koic/rubocop-rails that referenced this pull request Nov 11, 2020
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
koic added a commit to koic/rubocop-minitest that referenced this pull request Mar 21, 2021
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
koic added a commit to koic/rubocop-minitest that referenced this pull request Mar 21, 2021
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
koic added a commit to koic/rubocop-rake that referenced this pull request Aug 14, 2021
Follow up to rubocop/rubocop#8365.

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
koic added a commit to koic/rubocop-sequel that referenced this pull request Aug 20, 2021
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
koic added a commit that referenced this pull request Sep 3, 2021
renawatson68 added a commit to renawatson68/performance-develop-rubyonrails that referenced this pull request Sep 23, 2022
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
richardstewart0213 added a commit to richardstewart0213/performance-build-Performance-optimization-analysis- that referenced this pull request Nov 4, 2022
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
koic added a commit to koic/rubocop-airbnb that referenced this pull request Feb 27, 2023
Follow up rubocop/rubocop#8365.

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only.
https://docs.rubocop.org/rubocop/1.46/development.html#implementation
pariser pushed a commit to airbnb/ruby that referenced this pull request Feb 27, 2023
Follow up rubocop/rubocop#8365.

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only.
https://docs.rubocop.org/rubocop/1.46/development.html#implementation
koic added a commit to koic/rubocop-graphql that referenced this pull request Jun 22, 2023
Follow up rubocop/rubocop#8365.

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only.
https://docs.rubocop.org/rubocop/1.52/development.html#implementation

`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90, so it bumps the required lowest runtime
RuboCop dependency from 0.87 to 0.90. No runtime Ruby version incompatibilities between 0.87 and 0.90:
https://docs.rubocop.org/rubocop/1.52/compatibility.html
koic added a commit to koic/rubocop-graphql that referenced this pull request Jun 22, 2023
Follow up rubocop/rubocop#8365.

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only.
https://docs.rubocop.org/rubocop/1.52/development.html#implementation

`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90, so it bumps the required lowest runtime
RuboCop dependency from 0.87 to 0.90. No runtime Ruby version incompatibilities between 0.87 and 0.90:
https://docs.rubocop.org/rubocop/1.52/compatibility.html
DmitryTsepelev pushed a commit to DmitryTsepelev/rubocop-graphql that referenced this pull request Jun 22, 2023
Follow up rubocop/rubocop#8365.

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only.
https://docs.rubocop.org/rubocop/1.52/development.html#implementation

`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90, so it bumps the required lowest runtime
RuboCop dependency from 0.87 to 0.90. No runtime Ruby version incompatibilities between 0.87 and 0.90:
https://docs.rubocop.org/rubocop/1.52/compatibility.html
MarttiCheng added a commit to MarttiCheng/Rubocop-Performance that referenced this pull request Sep 28, 2023
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this pull request Oct 5, 2023
Follow rubocop/rubocop#8365

This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send`
to specific method names only.
`RESTRICT_ON_SEND` has been introduced since RuboCop 0.90.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants