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

[Refactor] improve performance for detecting class components #3267

Merged
merged 1 commit into from Apr 12, 2022

Conversation

golopot
Copy link
Contributor

@golopot golopot commented Apr 10, 2022

Benchmark on the eslint repo with extends: plugin:react/recommended and time npx eslint . (real time):

before after
run 1 8.0s 7.3s
run 2 7.8s 7.4s
run 3 8.0s 7.3s

Benchmark with TIMING=10 npx eslint .:

Before:

Rule                           | Time (ms) | Relative
:------------------------------|----------:|--------:
react/no-deprecated            |   762.467 |    21.0%
react/no-direct-mutation-state |   648.951 |    17.9%
react/display-name             |   635.527 |    17.5%
react/no-string-refs           |   531.934 |    14.7%
react/prop-types               |   387.259 |    10.7%
react/require-render-return    |   382.931 |    10.6%
react/no-children-prop         |   165.876 |     4.6%
react/jsx-no-comment-textnodes |    49.452 |     1.4%
react/no-unescaped-entities    |    19.529 |     0.5%
react/jsx-key                  |    14.197 |     0.4%

After:

Rule                           | Time (ms) | Relative
:------------------------------|----------:|--------:
react/no-deprecated            |   531.083 |    21.5%
react/no-direct-mutation-state |   466.098 |    18.8%
react/display-name             |   427.566 |    17.3%
react/no-string-refs           |   313.779 |    12.7%
react/require-render-return    |   251.905 |    10.2%
react/prop-types               |   245.300 |     9.9%
react/no-children-prop         |   141.999 |     5.7%
react/jsx-no-comment-textnodes |    39.487 |     1.6%
react/no-unescaped-entities    |    17.461 |     0.7%
react/jsx-key                  |    12.571 |     0.5%

@codecov-commenter
Copy link

codecov-commenter commented Apr 10, 2022

Codecov Report

Merging #3267 (161317e) into master (8992a2b) will decrease coverage by 0.00%.
The diff coverage is 92.30%.

@@            Coverage Diff             @@
##           master    #3267      +/-   ##
==========================================
- Coverage   97.69%   97.68%   -0.01%     
==========================================
  Files         121      121              
  Lines        8583     8593      +10     
  Branches     3120     3127       +7     
==========================================
+ Hits         8385     8394       +9     
- Misses        198      199       +1     
Impacted Files Coverage Δ
lib/util/Components.js 98.70% <92.30%> (-0.17%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8992a2b...161317e. Read the comment docs.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Changes in general look good!

lib/util/Components.js Outdated Show resolved Hide resolved
lib/util/Components.js Outdated Show resolved Hide resolved
Comment on lines +299 to +302
&& /^(Pure)?Component$/.test(node.superClass.property.name);
}
if (node.superClass.type === 'Identifier') {
return /^(Pure)?Component$/.test(node.superClass.name);
Copy link
Member

Choose a reason for hiding this comment

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

is there a speed improvement from caching this non-global regex at module level?

Copy link
Contributor Author

@golopot golopot Apr 12, 2022

Choose a reason for hiding this comment

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

I tried and didn't see a speed improvement. I suppose the compiler can compile the regexp once and reuse it afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This contrasts with the previous line RegExp(^(${pragma}\.)?(Pure)?Component$) where v8 have to compile the regexp at runtime at every function call.

Copy link
Member

Choose a reason for hiding this comment

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

we'll land it as-is then for now

@ljharb ljharb merged commit 161317e into jsx-eslint:master Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants