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

perf: improve prefer-node-protocol's performance #406

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pralkarz
Copy link

@pralkarz pralkarz commented Jan 21, 2025

Closes #404.

The main change is avoiding an expensive iteration with ReferenceTracker.iterateGlobalReferences by operating directly on ESLint's CallExpressions. I've used a similar approach for ESM imports/exports too rather than sticking with "Program:exit".

Benchmarks and smoke tests were done in the Svelte repository. Both reporting and --fixing works as expected.

master branch:

Rule                                            | Time (ms) | Relative
:-----------------------------------------------|----------:|--------:
n/prefer-node-protocol                          |   902.571 |    51.8%

prefer-node-protocol-performance branch:

Rule                                            | Time (ms) | Relative
:-----------------------------------------------|----------:|--------:
n/prefer-node-protocol                          |    46.429 |     5.2%

The main change is avoiding an expensive iteration with
`ReferenceTracker.iterateGlobalReferences` by operating directly on
ESLint's `CallExpression`s.
@scagood
Copy link

scagood commented Jan 23, 2025

Awesome work on both the investigation and the PR for the fix. Thank you!

Everything looks great, but could you revert the Reduce the diff (hopefully) commit please 😅
I think having the functions at the top level is much better!

@pralkarz
Copy link
Author

pralkarz commented Jan 23, 2025

I think having the functions at the top level is much better!

I also prefer that, but I put them back in create since that's what it was like before, and I didn't want to overwhelm you with a bigger diff than necessary. Reverted now though. 😄

Copy link

@scagood scagood left a comment

Choose a reason for hiding this comment

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

🤩 Thank you

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.

perf: n/prefer-node-protocol could use optimization
2 participants