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
Chore: improve performance of indent
rule
#8905
Conversation
This updates the `indent` rule to be more performant by storing information ranges of tokens rather than performing operations on many individual tokens one-at-a-time.
LGTM |
@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vitorbal, @gyandeeps and @Trott to be potential reviewers. |
@@ -46,6 +46,7 @@ | |||
"estraverse": "^4.2.0", | |||
"esutils": "^2.0.2", | |||
"file-entry-cache": "^2.0.0", | |||
"functional-red-black-tree": "^1.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I marked this PR as WIP because this module appears to be unmaintained. Its readme also mentions that the immutable approach ends up hurting performance for consumers that don't need immutability. We might be able to get an even larger performance boost if we implement our own balanced BST (or use a different maintained module, but I had trouble finding another balanced BST module that has the features we need).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to unmark this as WIP because I looked for more balanced BST libraries and didn't find any good alternatives at the moment. I also tried implementing one myself for awhile, but balanced BSTs are relatively complicated and difficult to get right, so it's probably not worth adding an implementation to the repo if this module is working for us right now.
indent
ruleindent
rule
LGTM |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice perf boost.
LGTM |
I've made a few small improvements -- now this improves end-to-end performance by 20%. Benchmark
(I think my laptop has a different battery level than when I ran the benchmark in the original PR, so these two runs are comparable to each other, but they're not comparable to the original two runs in terms of absolute time.) |
What is the purpose of this pull request? (put an "X" next to item)
[x] Other, please explain:
What changes did you make? (Give an overview)
This updates the
indent
rule to be more performant by storing information on ranges of tokens rather than performing operations on many individual tokens one-at-a-time.This results in a 19% end-to-end performance increase (!) according to our
npm run perf
benchmark.End-to-end benchmark
master
branch:indent-performance
branch:Rule-specific benchmark on ESLint codebase
master
branch:indent-performance
branch:Is there anything you'd like reviewers to focus on?
I tried to write descriptive comments to explain what's going on. Is there anything that's unclear or could be improved?