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

Speed up no-exclusive-tests and no-pending-tests #276

Merged
merged 6 commits into from
Mar 5, 2021

Conversation

szuend
Copy link
Contributor

@szuend szuend commented Mar 5, 2021

The isDescribe and isTestCase are doing a lot of work that is unnecessarily redone on each call expression.
This PR moves this work upfront, when the rule is created and re-uses the result for each call expression.

Please note that the choosen implementation is not a strong opinion. I tried to keep the code churn to a minimum and not export more astUtils internals. Feel free to suggest how you prefer this to be solved differently.

We noticed the performance while linting the DevTools frontend. Running with the following command line:

TIMING=1 third_party/node/node.py --output scripts/test/run_lint_check_js.js

Before the change:

Rule                                 | Time (ms) | Relative
:------------------------------------|----------:|--------:
mocha/no-exclusive-tests             |  3697.734 |    35.9%
mocha/no-pending-tests               |  2133.972 |    20.7%
@typescript-eslint/naming-convention |   761.571 |     7.4%
no-whitespace-before-property        |   373.331 |     3.6%
keyword-spacing                      |   359.593 |     3.5%
space-infix-ops                      |   266.812 |     2.6%
@typescript-eslint/func-call-spacing |   180.198 |     1.8%
space-in-parens                      |   175.388 |     1.7%
@typescript-eslint/comma-dangle      |   164.089 |     1.6%
no-trailing-spaces                   |   144.546 |     1.4%

After the change (the two eslint-plugin-mocha rules we use no longer show up in the TOP 10):

Rule                                 | Time (ms) | Relative
:------------------------------------|----------:|--------:
@typescript-eslint/naming-convention |   758.180 |    17.2%
no-whitespace-before-property        |   348.997 |     7.9%
keyword-spacing                      |   336.037 |     7.6%
space-infix-ops                      |   250.037 |     5.7%
space-in-parens                      |   215.183 |     4.9%
@typescript-eslint/func-call-spacing |   147.527 |     3.4%
@typescript-eslint/comma-dangle      |   144.443 |     3.3%
rulesdir/es_modules_import           |   127.713 |     2.9%
no-trailing-spaces                   |   122.335 |     2.8%
comma-style                          |   112.220 |     2.5%

@lo1tuma
Copy link
Owner

lo1tuma commented Mar 5, 2021

Nice! Thank you for that contribution. I’ve also already started work on a major refactoring of astUtils to also address this and a few other issues, but it is a big change and still not finished yet. So I really appreciate such a small change that improves the performance significantly.

In order to further decrease the performance I’ve introduce a benchmark test and set a performance budget. Can you check out this benchmark whether we can reduce the budged with this PR? See https://github.com/lo1tuma/eslint-plugin-mocha/blob/faa8bbf7dcd2a8f22bfe76a3a47b03bb678c2284/benchmarks/runtime.bench.js#L88.

@szuend
Copy link
Contributor Author

szuend commented Mar 5, 2021

Thanks for the really fast answer! The speed numbers that os.cpus() reports for my workstation are fluctuating quite heavily so I choose the new boundary rather conservatively.

I'd like to extend this approach for isDescribe and isTestCase to other rules that could benefit from them (but not other astUtils functions). Would you prefer a separate PR to keep commits small or should I modify this PR?

Copy link
Owner

@lo1tuma lo1tuma left a comment

Choose a reason for hiding this comment

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

Thanks. I would say let’s ship those changes. For further performance improvements we can create follow-up PRs.

@lo1tuma lo1tuma changed the title Speed up AST utils Speed up no-exclusive-tests and no-pending-tests Mar 5, 2021
@lo1tuma lo1tuma merged commit 5bec7fe into lo1tuma:master Mar 5, 2021
This was referenced Mar 8, 2021
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.

2 participants