Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jul 23, 2025

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).

@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Jul 23, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@overlookmotel overlookmotel marked this pull request as ready for review July 23, 2025 12:35
@overlookmotel overlookmotel force-pushed the 07-22-perf_napi_oxlint_optimize_compiling_visitor branch 2 times, most recently from 6c80f89 to bbfce85 Compare July 23, 2025 12:36
@overlookmotel overlookmotel requested a review from camc314 July 23, 2025 13:14
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

this is crazy

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Jul 23, 2025
Copy link
Contributor

camc314 commented Jul 23, 2025

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).
@graphite-app graphite-app bot force-pushed the 07-22-perf_napi_oxlint_optimize_compiling_visitor branch from bbfce85 to 6e8d219 Compare July 23, 2025 13:19
@overlookmotel
Copy link
Member Author

@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.

@camc314
Copy link
Contributor

camc314 commented Jul 23, 2025

no, rule order doesn't matter

@camc314
Copy link
Contributor

camc314 commented Jul 23, 2025

Let me add a check so that when running tests, we always sort the diagnostics

Actually sorting is really hard as it'll interfere with the other diagnostics

@graphite-app graphite-app bot merged commit 6e8d219 into main Jul 23, 2025
15 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jul 23, 2025
@graphite-app graphite-app bot deleted the 07-22-perf_napi_oxlint_optimize_compiling_visitor branch July 23, 2025 13:26
@overlookmotel
Copy link
Member Author

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)

@camc314
Copy link
Contributor

camc314 commented Jul 23, 2025

Oh you've actually hit an edge case:

self.diagnostics.sort_by_key(|diagnostic| Info::new(diagnostic).filename);
self.diagnostics.sort_by_key(|diagnostic| Info::new(diagnostic).start.line);

we already sort by filename, start/end line. but since these both have the same filename/start/end line, the order changes

graphite-app bot pushed a commit that referenced this pull request Jul 23, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-performance Category - Solution not expected to change functional behavior, only performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants