-
-
Notifications
You must be signed in to change notification settings - Fork 724
perf(napi/oxlint): optimize compiling visitor #12472
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(napi/oxlint): optimize compiling visitor #12472
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
6c80f89 to
bbfce85
Compare
camc314
left a comment
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.
this is crazy
Merge activity
|
Optimize merging together visitors from multiple rules. The merging itself is a bit faster. More importantly, the merged visitor functions are more optimizable by the JS engine, which makes calling them less expensive. In a benchmark running 3 rules which all visit the same common AST nodes (identifiers) on VS Code repo, this speeds up `lintFile` by 30% on average, giving an overall speed-up of 15% (when no built-in Oxlint rules enabled).
bbfce85 to
6e8d219
Compare
|
@camc314 This can change the order that rules run in, so output diagnostics can appear in different order from the order the rules are defined in config. I don't think that matters, right? If it does, could amend this PR to ensure rules run in original order. It'd just make compiling visitors a little slower. |
|
no, rule order doesn't matter |
|
Actually sorting is really hard as it'll interfere with the other diagnostics |
|
The order rules run in (and therefore order they output diagnostics) is deterministic. It's just not necessarily in the order the rules are defined in config. Obviously, determinism will go out the window once we introduce multi-threading! (although that'll affect the order files are linted in, not the order rules run in for each file) |
|
Oh you've actually hit an edge case: oxc/apps/oxlint/src/output_formatter/default.rs Lines 135 to 136 in 1d2eaca
we already sort by filename, start/end line. but since these both have the same filename/start/end line, the order changes |
Fix a bug introduced in #12472. It's possible for a rule to generate diagnostics in `create` even if it doesn't visit the AST. Following PR adds tests for this.

Optimize merging together visitors from multiple rules.
The merging itself is a bit faster. More importantly, the merged visitor functions are more optimizable by the JS engine, which makes calling them less expensive.
In a benchmark running 3 rules which all visit the same common AST nodes (identifiers) on VS Code repo, this speeds up
lintFileby 30% on average, giving an overall speed-up of 15% (when no built-in Oxlint rules enabled).