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

Small Style cops perf tweaks #8359

Merged
merged 1 commit into from Aug 5, 2020

Conversation

fatkodima
Copy link
Contributor

Ran on discourse codebase:

$ bin/rubocop-profile --force-default-config --cache false --only Style ../discourse

Before

     5228  (    9.0%)  RuboCop::Cop::Style::RedundantSelf#on_block
     3376  (    5.8%)  RuboCop::Cop::StringHelp#on_str
 1   1975  (    3.4%)  RuboCop::Cop::Style::AccessModifierDeclarations#on_send
 2   1960  (    3.4%)  RuboCop::Cop::Style::FormatStringToken#on_str
     1712  (    2.9%)  RuboCop::Cop::Style::TrailingCommaInArguments#on_send
 3   1560  (    2.7%)  RuboCop::Cop::Style::NumericPredicate#on_send
     1471  (    2.5%)  RuboCop::Cop::Style::ConditionalAssignment#on_send
 4   1453  (    2.5%)  RuboCop::Cop::Style::MethodCallWithoutArgsParentheses#on_send
 5   1278  (    2.2%)  RuboCop::Cop::Style::ZeroLengthPredicate#on_send
 6   1150  (    2.0%)  RuboCop::Cop::Style::RedundantSort#on_send
 7   1041  (    1.8%)  RuboCop::Cop::Style::InverseMethods#on_send
      982  (    1.7%)  RuboCop::Cop::StringHelp#on_str
 8    974  (    1.7%)  RuboCop::Cop::Style::SignalException#on_send
      964  (    1.7%)  RuboCop::Cop::Style::BlockDelimiters#on_send
 9    962  (    1.7%)  RuboCop::Cop::Style::HashSyntax#on_hash
      939  (    1.6%)  RuboCop::Cop::Style::RedundantSelf#on_def
 10   913  (    1.6%)  RuboCop::Cop::Style::ColonMethodCall#on_send
 11   864  (    1.5%)  RuboCop::Cop::Style::EvalWithLocation#on_send
 12   851  (    1.5%)  RuboCop::Cop::Style::ExpandPathArguments#on_send
      829  (    1.4%)  RuboCop::Cop::Style::EmptyLiteral#on_send
 13   791  (    1.4%)  RuboCop::Cop::Style::FormatString#on_send
      784  (    1.3%)  RuboCop::Cop::Style::NonNilCheck#on_send
 14   777  (    1.3%)  RuboCop::Cop::Style::RedundantException#on_send
      777  (    1.3%)  RuboCop::Cop::Style::StabbyLambdaParentheses#on_send
      767  (    1.3%)  RuboCop::Cop::Style::NestedParenthesizedCalls#on_send
 15   749  (    1.3%)  RuboCop::Cop::Style::RandomWithOffset#on_send
      724  (    1.2%)  RuboCop::Cop::Style::NilComparison#on_send

After

    4277  (   12.4%)  RuboCop::Cop::Style::RedundantSelf#on_block
    2307  (    6.7%)  RuboCop::Cop::StringHelp#on_str
    1167  (    3.4%)  RuboCop::Cop::Style::TrailingCommaInArguments#on_send
    1159  (    3.4%)  RuboCop::Cop::Style::ConditionalAssignment#on_send
     730  (    2.1%)  RuboCop::Cop::Style::RedundantSelf#on_def
     707  (    2.0%)  RuboCop::Cop::StringHelp#on_str
     688  (    2.0%)  RuboCop::Cop::Style::BlockDelimiters#on_send
     633  (    1.8%)  RuboCop::Cop::Style::EmptyLiteral#on_send
     570  (    1.6%)  RuboCop::Cop::Style::StabbyLambdaParentheses#on_send
 7   556  (    1.6%)  RuboCop::Cop::Style::InverseMethods#on_send
     538  (    1.6%)  RuboCop::Cop::Style::NonNilCheck#on_send
     523  (    1.5%)  RuboCop::Cop::Style::NestedParenthesizedCalls#on_send
     506  (    1.5%)  RuboCop::Cop::Style::Sample#on_send
     477  (    1.4%)  RuboCop::Cop::Style::FloatDivision#on_send
     469  (    1.4%)  RuboCop::Cop::Style::NilComparison#on_send
     460  (    1.3%)  RuboCop::Cop::Style::UnpackFirst#on_send
 1   446  (    1.3%)  RuboCop::Cop::Style::AccessModifierDeclarations#on_send
10   445  (    1.3%)  RuboCop::Cop::Style::ColonMethodCall#on_send
     443  (    1.3%)  RuboCop::Cop::Style::CaseEquality#on_send
 8   418  (    1.2%)  RuboCop::Cop::Style::SignalException#on_send
     400  (    1.2%)  RuboCop::Cop::Style::IfUnlessModifier#on_if
     398  (    1.2%)  RuboCop::Cop::Style::StderrPuts#on_send
     394  (    1.1%)  RuboCop::Cop::Style::ArrayJoin#on_send
     392  (    1.1%)  RuboCop::Cop::Style::Strip#on_send
     382  (    1.1%)  RuboCop::Cop::Style::Dir#on_send
     381  (    1.1%)  RuboCop::Cop::Style::EvenOdd#on_send
     364  (    1.1%)  RuboCop::Cop::Style::PreferredHashMethods#on_send
 3   362  (    1.0%)  RuboCop::Cop::Style::NumericPredicate#on_send
     335  (    1.0%)  RuboCop::Cop::StringHelp#on_str
     333  (    1.0%)  RuboCop::Cop::Style::MixinUsage#on_send
     332  (    1.0%)  RuboCop::Cop::Style::YodaCondition#on_send
     330  (    1.0%)  RuboCop::Cop::Style::Documentation#on_class
 5   328  (    0.9%)  RuboCop::Cop::Style::ZeroLengthPredicate#on_send
     318  (    0.9%)  RuboCop::Cop::Style::RaiseArgs#on_send
     312  (    0.9%)  RuboCop::Cop::Style::BlockDelimiters#on_block
     308  (    0.9%)  RuboCop::Cop::Style::Semicolon#on_begin
     306  (    0.9%)  RuboCop::Cop::Style::ClassCheck#on_send
     305  (    0.9%)  RuboCop::Cop::Style::BarePercentLiterals#on_str
     305  (    0.9%)  RuboCop::Cop::Style::Not#on_send

@@ -96,6 +98,14 @@ def on_send(node)

private

def access_modifier?(node)
maybe_access_modifier?(node) && node.access_modifier?
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine, but shouldn't it be Node#access_modifier? itself that should be sped up instead of just this cop? I think just changing the order of the conditions in rubocop-ast should give you most of the speed up, but I may be wrong

@@ -53,6 +55,8 @@ class FormatString < Cop
PATTERN

def on_send(node)
return unless FORMAT_METHODS.include?(node.method_name)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a pattern that comes back very often for on_send, right? It wouldn't be too hard to tweak Commissionner so that a Cop could specify a list of method_name to be called for (and not be bothered for others); it would be quite fast. Useful?

Copy link
Contributor

Choose a reason for hiding this comment

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

@marcandre I'd find that incredibly useful for many cops I write.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool :-) Please check #8365 and let me know how well that fits what you'd like. It could be made more general but I think that on_send and node.method_name are by far the most important checks.

@bbatsov bbatsov merged commit 6042aed into rubocop:master Aug 5, 2020
@marcandre
Copy link
Contributor

This broke the build ("Unnecessary disabling of Metrics/AbcSize"), now that the AbcSize has changed... Makes sense that the spec suite for the open PRs aren't re-run all the time 🤷‍♂️

I'm on it.

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

4 participants