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
Conversation
ping @bbatsov |
ping @bbatsov Let me know if my ping frequency is too high too 😅 |
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. |
Cool. I'll document this and then merge. Thanks! |
14ea0c1
to
dd2574f
Compare
0968c72
to
c703039
Compare
c703039
to
e9173bb
Compare
e9173bb
to
7ca29a9
Compare
7ca29a9
to
a0f10f9
Compare
@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. |
16% is awesome, especially given the minimal trouble it is to specify it! 🎉 |
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.
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.
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.
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.
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.
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.
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.
Follow up to rubocop/rubocop#8365. This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only.
Follow rubocop/rubocop#8365 This PR uses `RESTRICT_ON_SEND` to restrict callbacks `on_send` to specific method names only.
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.
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.
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
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
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
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
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
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.
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.
Many of the recent optimizations for Cops seem to be to modify
on_send
to check early for thenode.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 10kSendNode
, if these cops are optimized with the first thing inon_send
beingreturn if SOME_LIST.include?(node.method_name)
, there would still be 100*10k calls toon_send
, and 100*10k calls toSet#include?
(assuming thatSOME_LIST
is aSet
, 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