perf(linter/plugins): add fast path for files with no comments#20366
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
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. |
f7daa9a to
b7af7fc
Compare
dfe4809 to
0af44c0
Compare
320dfb8 to
3f0a4f0
Compare
dcbfe5f to
03c2e4b
Compare
There was a problem hiding this comment.
Pull request overview
Adds a performance optimization in the oxlint JS plugin layer by short-circuiting comment initialization for files that contain zero comments, reducing work in a common case.
Changes:
- Add a shared frozen empty comments array and return early from
initComments()whencommentsLen === 0. - Minor refactor/simplification of a string replacement in the TypeScript type generator.
Reviewed changes
Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
apps/oxlint/src-js/plugins/comments.ts |
Introduces the no-comments fast path and shared empty comments array. |
tasks/ast_tools/src/generators/typescript.rs |
Collapses a multi-line replacen call into a single line. |
3f0a4f0 to
4a39359
Compare
03c2e4b to
10b9cf7
Compare
4a39359 to
b9c061d
Compare
There was a problem hiding this comment.
Pull request overview
Adds a fast-path in the JS-side comment deserialization to avoid work for files with zero comments (a common case), while preserving the existing initComments() contract that sourceText is initialized after initialization.
Changes:
- Add a shared, reusable empty comments array and early-return in
initComments()whencommentsLen === 0. - Minor tweak to hashbang/shebang detection logic during comment initialization.
- Update oxlint NAPI bindings exports/types (notably removing
Severityand several type declarations).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| apps/oxlint/src-js/plugins/comments.ts | Adds an early-exit fast path for commentless files and reuses a shared empty comments array. |
| apps/oxlint/src-js/bindings.js | Stops exporting Severity from the JS bindings surface. |
| apps/oxlint/src-js/bindings.d.ts | Removes Severity and other previously exported interfaces from the generated TS declarations. |
Comments suppressed due to low confidence (1)
apps/oxlint/src-js/bindings.js:586
- This PR is described as a comments deserialization perf-only change, but this hunk stops exporting
Severityfrom the oxlint JS bindings. If this export is still part of the expected bindings surface (consistent with other NAPI packages in this repo likenapi/parserandapps/oxfmt), this is a breaking change and should either be reverted or called out explicitly (and versioned accordingly).
const { applyFixes, getBufferOffset, lint, parseRawSync, rawTransferSupported } = nativeBinding
export { applyFixes }
export { getBufferOffset }
export { lint }
export { parseRawSync }
| // then `sourceText` is initialized. Doing it eagerly here avoid having to check if `sourceText` is null | ||
| // in all those methods, which can be called quite frequently. |

Optimization to comments deserialization. Files which have no comments are probably fairly common. Add a fast path for this case. We have to branch on
length === 0later on anyway, so might as well branch earlier and exit.