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

Rewrite Layout/SpaceAroundMethodCallOperator cop to make it faster #8300

Conversation

fatkodima
Copy link
Contributor

Closes #8021

Before

Finished in 44.9 seconds

$ rake prof:slow_cops

stackprof tmp/stackprof.dump --text --method 'RuboCop::Cop::Commissioner#trigger_responding_cops'
    4065  (   18.0%)  RuboCop::Cop::Layout::SpaceAroundMethodCallOperator#on_send   <========== 1
     509  (    2.3%)  RuboCop::Cop::Style::TrailingMethodEndStatement#on_def
     386  (    1.7%)  RuboCop::Cop::Layout::IndentationConsistency#on_begin
     369  (    1.6%)  RuboCop::Cop::Style::NumericPredicate#on_send
     337  (    1.5%)  RuboCop::Cop::MultilineExpressionIndentation#on_send
     299  (    1.3%)  RuboCop::Cop::Layout::FirstArgumentIndentation#on_send
     285  (    1.3%)  RuboCop::Cop::Lint::DuplicateMethods#on_def
     274  (    1.2%)  RuboCop::Cop::Metrics::ModuleLength#on_module
     269  (    1.2%)  RuboCop::Cop::Layout::DefEndAlignment#on_send
     264  (    1.2%)  RuboCop::Cop::Performance::FixedSize#on_send
     243  (    1.1%)  RuboCop::Cop::Lint::NestedMethodDefinition#on_def
     238  (    1.1%)  RuboCop::Cop::Layout::DotPosition#on_send
     235  (    1.0%)  RuboCop::Cop::Layout::SpaceInsideReferenceBrackets#on_send
     216  (    1.0%)  RuboCop::Cop::Metrics::MethodLength#on_def
     212  (    0.9%)  RuboCop::Cop::Layout::ArgumentAlignment#on_send
     211  (    0.9%)  RuboCop::Cop::MethodComplexity#on_def
     194  (    0.9%)  RuboCop::Cop::Layout::LineLength#on_potential_breakable_node
     188  (    0.8%)  RuboCop::Cop::Lint::DeprecatedClassMethods#on_send
     175  (    0.8%)  RuboCop::Cop::Lint::MixedRegexpCaptureTypes#on_regexp
     173  (    0.8%)  RuboCop::Cop::Layout::SpaceAroundMethodCallOperator#on_const    <========== 2
     171  (    0.8%)  RuboCop::Cop::Naming::VariableName#on_lvasgn
     170  (    0.8%)  RuboCop::Cop::Layout::SpaceInsideHashLiteralBraces#on_hash

After

Finished in 37.1 seconds

stackprof tmp/stackprof.dump --text --method 'RuboCop::Cop::Commissioner#trigger_responding_cops'
     440  (    2.8%)  RuboCop::Cop::Style::TrailingMethodEndStatement#on_def
     342  (    2.2%)  RuboCop::Cop::Layout::IndentationConsistency#on_begin
     286  (    1.8%)  RuboCop::Cop::MultilineExpressionIndentation#on_send
     285  (    1.8%)  RuboCop::Cop::Style::NumericPredicate#on_send
     262  (    1.7%)  RuboCop::Cop::Metrics::ModuleLength#on_module

Both lines disappeared from the profile and gave 20% speedup overall.

@marcandre
Copy link
Contributor

Awesome 🎉

@marcandre marcandre merged commit 1c9809d into rubocop:master Jul 10, 2020
@marcandre
Copy link
Contributor

So much cleaner and shorter too, great job!

@nertzy
Copy link

nertzy commented Jul 13, 2020

We are seeing issues when this is used with the Proc call shorthand like this:

square = Proc.new {|x| x**2 }

square.(3)      #=> 9

@marcandre
Copy link
Contributor

marcandre commented Jul 13, 2020

Thanks @nertzy

@fatkodima, should we create an issue for this or will you check it out directly? Nevermind. #8324

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.

Layout/SpaceAroundMethodCallOperator is slow
3 participants