Skip to content

perf(linter/plugins): add fast path for files with no comments#20366

Open
overlookmotel wants to merge 1 commit intoom/03-13-fix_linter_plugins_remove_hashbang_property_from_astfrom
om/03-14-perf_linter_plugins_add_fast_path_for_files_with_no_comments
Open

perf(linter/plugins): add fast path for files with no comments#20366
overlookmotel wants to merge 1 commit intoom/03-13-fix_linter_plugins_remove_hashbang_property_from_astfrom
om/03-14-perf_linter_plugins_add_fast_path_for_files_with_no_comments

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 14, 2026

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.

Copy link
Member Author

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.
Learn more


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 changes, fast-track this PR to the front of 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.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins C-performance Category - Solution not expected to change functional behavior, only performance labels Mar 14, 2026
@overlookmotel overlookmotel force-pushed the om/03-13-fix_linter_plugins_remove_hashbang_property_from_ast branch from f7daa9a to b7af7fc Compare March 14, 2026 01:51
@overlookmotel overlookmotel force-pushed the om/03-14-perf_linter_plugins_add_fast_path_for_files_with_no_comments branch from dfe4809 to 0af44c0 Compare March 14, 2026 01:51
@github-actions github-actions bot added the A-ast-tools Area - AST tools label Mar 14, 2026
@overlookmotel overlookmotel marked this pull request as ready for review March 14, 2026 02:01
@overlookmotel overlookmotel requested a review from camc314 as a code owner March 14, 2026 02:01
Copilot AI review requested due to automatic review settings March 14, 2026 02:01
@overlookmotel overlookmotel force-pushed the om/03-14-perf_linter_plugins_add_fast_path_for_files_with_no_comments branch from 320dfb8 to 3f0a4f0 Compare March 14, 2026 02:03
@overlookmotel overlookmotel force-pushed the om/03-13-fix_linter_plugins_remove_hashbang_property_from_ast branch from dcbfe5f to 03c2e4b Compare March 14, 2026 02:03
@overlookmotel overlookmotel self-assigned this Mar 14, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() when commentsLen === 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.

@overlookmotel overlookmotel force-pushed the om/03-14-perf_linter_plugins_add_fast_path_for_files_with_no_comments branch from 3f0a4f0 to 4a39359 Compare March 14, 2026 02:11
@overlookmotel overlookmotel force-pushed the om/03-13-fix_linter_plugins_remove_hashbang_property_from_ast branch from 03c2e4b to 10b9cf7 Compare March 14, 2026 02:11
@overlookmotel overlookmotel force-pushed the om/03-14-perf_linter_plugins_add_fast_path_for_files_with_no_comments branch from 4a39359 to b9c061d Compare March 14, 2026 02:29
@overlookmotel overlookmotel requested a review from Copilot March 14, 2026 02:30
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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() when commentsLen === 0.
  • Minor tweak to hashbang/shebang detection logic during comment initialization.
  • Update oxlint NAPI bindings exports/types (notably removing Severity and 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 Severity from the oxlint JS bindings. If this export is still part of the expected bindings surface (consistent with other NAPI packages in this repo like napi/parser and apps/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 }

Comment on lines +99 to +100
// 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins 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.

2 participants