perf(linter/plugins): add fast path for files with no comments#20366
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. |
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 }
10b9cf7 to
f8fbd6e
Compare
b9c061d to
7f9bf2c
Compare
7f9bf2c to
cf1a313
Compare
cf1a313 to
0bc8d0f
Compare
There was a problem hiding this comment.
Pull request overview
Adds a fast path in the JS-side comments deserializer to avoid per-file comment object setup work when the parsed program contains zero comments, which should reduce overhead for common “no comments” files during lint runs.
Changes:
- Introduces a shared frozen
emptyCommentsarray and returns it early whencommentsLen === 0. - Keeps
sourceTextinitialization eager ininitComments()to preserve existing invariants for downstream comment APIs. - Simplifies hashbang (
Shebang) detection by checking the first serialized comment’s start offset directly.
Merge activity
|
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 === 0` later on anyway, so might as well branch earlier and exit.
0bc8d0f to
618a598
Compare
# Oxlint ### 🚀 Features - c95951f linter/plugins: Implement `sourceCode.markVariableAsUsed` (#20357) (overlookmotel) - 7a2a7d0 linter: Implement `n/handle-callback-err` rule (#19616) (Mikhail Baev) ### 🐛 Bug Fixes - f8fbd6e linter/plugins: Remove `hashbang` property from AST (#20365) (overlookmotel) - 6eb5b01 linter/prefer-await-to-then: Ignore Promise static methods (#20347) (camc314) - a4b61f7 linter: Remove `defineConfig` check (#20308) (camc314) - 3ad7f53 linter/explicit-module-boundary-types: False positive with satisfies expr (#20309) (camc314) - f547401 linter/no-unused-private-class-members: Treat switch discriminants as read (#20307) (camc314) - 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen) ### ⚡ Performance - e4f7248 linter: Remove unnecessary clone of owned String in drain loop (#20388) (Boshen) - 4a67f1d linter: Eliminate Vec allocation in disable directive matching (#20387) (Boshen) - 618a598 linter/plugins: Add fast path for files with no comments (#20366) (overlookmotel) - b0125c5 linter/plugins: Deserialize comments without AST (#20364) (overlookmotel) - 9cd612f linter/plugins: Recycle comment objects (#20362) (overlookmotel) - bf442f8 linter/plugins: Cheaper `Token` creation (#20360) (overlookmotel) - 5474d0a semantic: V8-style walk-up reference resolution (#20292) (Boshen) - 7946eba linter/plugins: Avoid arguments spread and temp array when merging (#20318) (overlookmotel) - fc7cf8a linter/plugins: Pre-define less CFG merger functions (#20317) (overlookmotel) - 3b9eb28 linter/plugins: Streamline getting/creating visit fn mergers (#20319) (overlookmotel) - f04e850 linter/plugins: Inline binary search functions into call sites (#20312) (overlookmotel) - fe24afe linter/plugins: Apply replace globals TSDown plugin to JS files (#20305) (overlookmotel) - 77cdacc linter/plugins: Use array buffer views for tokens (#20301) (overlookmotel) - 910c941 linter/plugins: Reorder branches in `getTokenByRangeStart` (#20296) (overlookmotel) - af7674c linter/tokens: Avoid extra token value allocation (#20013) (camc314) ### 📚 Documentation - 24490b5 linter: Improve formatting for 80ish rules' docs. (#20411) (connorshea) - 3383523 linter: Improve `--tsconfig` flag docs (#20342) (camc314) # Oxfmt ### 🚀 Features - d22c443 oxfmt: Export `OxfmtConfig` type (#20275) (leaysgur) - a11ecff oxfmt/lsp: Respect `angular` language id as `.component.html` file (#20242) (Sysix) ### 🐛 Bug Fixes - ce65099 formatter: Preserve parentheses around as expression before private field access (#20419) (bab) - f908742 oxfmt: Revert #20326 partially (#20413) (leaysgur) - 4ef93ea formatter: Honor trailing ignore comments after list separators (#19925) (Andreas Lubbe) - 68fb0d0 oxfmt: Skip vite.config.ts which fails to import (#20326) (leaysgur) - 88ee826 oxfmt: Handle literalline for script-in-vue (#20130) (leaysgur) - 1c07b3b diagnostics: Handle `WouldBlock` in stdout writes to prevent panic (#20295) (Boshen) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>

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.