Skip to content

Comments

perf(parser): faster checking for invalid modifiers#15717

Merged
graphite-app[bot] merged 1 commit intomainfrom
11-15-perf_parser_faster_checking_for_invalid_modifiers
Nov 16, 2025
Merged

perf(parser): faster checking for invalid modifiers#15717
graphite-app[bot] merged 1 commit intomainfrom
11-15-perf_parser_faster_checking_for_invalid_modifiers

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Nov 15, 2025

Modifiers contains 2 different representations of the modifiers list:

  • ModifierFlags bitflags
  • Vec<Modifier>

When checking modifiers, use ModifierFlags (which is really cheap), rather than iterating through the Vec<Modifier> (more expensive).

Only if the first check fails, then loop through the Vec to get the spans of the invalid modifiers, and generate diagnostics.

Because invalid modifiers are rare, move the logic for looping through the Vec into a #[cold] #[inline(never)] function. This should make it possible to inline verify_modifiers into all the call sites.

Produces a small perf improvement on parser benchmarks (+0.1% - +0.2%).

@github-actions github-actions bot added A-parser Area - Parser C-performance Category - Solution not expected to change functional behavior, only performance labels Nov 15, 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.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 15, 2025

CodSpeed Performance Report

Merging #15717 will not alter performance

Comparing 11-15-perf_parser_faster_checking_for_invalid_modifiers (624bb75) with main (d8d4e31)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (4608549) during the generation of this report, so d8d4e31 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel force-pushed the 11-15-perf_parser_faster_checking_for_invalid_modifiers branch 2 times, most recently from 17bfdde to 624bb75 Compare November 15, 2025 15:12
@overlookmotel overlookmotel marked this pull request as ready for review November 15, 2025 15:12
Copilot AI review requested due to automatic review settings November 15, 2025 15:12
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

This PR optimizes the modifier checking logic in the parser by using bitflag operations instead of iterating through vectors. The key performance improvement comes from checking ModifierFlags (bitflags) first, and only looping through the Vec<Modifier> to get spans for diagnostics when invalid modifiers are detected.

Key changes:

  • Added contains_all_flags method to check multiple flags efficiently
  • Refactored verify_modifiers to use bitflag intersection check before iterating modifiers
  • Moved error reporting logic into a #[cold] #[inline(never)] function to enable better inlining of the main verification function

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/oxc_parser/src/modifiers.rs Added contains_all_flags method and refactored verify_modifiers to check bitflags first, with cold error reporting path
crates/oxc_parser/src/js/class.rs Updated all verify_modifiers call sites to use bitflag negation syntax and adapted to new diagnostic function signatures
crates/oxc_parser/src/ts/types.rs Replaced manual loop with verify_modifiers call using bitflag negation
crates/oxc_parser/src/diagnostics.rs Updated modifiers_cannot_appear_here signature to match standard modifier diagnostic pattern

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overlookmotel overlookmotel requested a review from Boshen November 15, 2025 16:51
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Nov 16, 2025
Copy link
Member

Boshen commented Nov 16, 2025

Merge activity

`Modifiers` contains 2 different representations of the modifiers list:

* `ModifierFlags` bitflags
* `Vec<Modifier>`

When checking modifiers, use `ModifierFlags` (which is really cheap), rather than iterating through the `Vec<Modifier>` (more expensive).

Only if the first check fails, then loop through the `Vec` to get the spans of the invalid modifiers, and generate diagnostics.

Because invalid modifiers are rare, move the logic for looping through the `Vec` into a `#[cold]` `#[inline(never)]` function. This should make it possible to inline `verify_modifiers` into all the call sites.

Produces a small perf improvement on parser benchmarks (+0.1% - +0.2%).
@graphite-app graphite-app bot force-pushed the 11-15-perf_parser_faster_checking_for_invalid_modifiers branch from 624bb75 to 1f09d3c Compare November 16, 2025 03:06
@graphite-app graphite-app bot merged commit 1f09d3c into main Nov 16, 2025
21 checks passed
@graphite-app graphite-app bot deleted the 11-15-perf_parser_faster_checking_for_invalid_modifiers branch November 16, 2025 03:14
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Nov 16, 2025
graphite-app bot pushed a commit that referenced this pull request Nov 17, 2025
### 💥 BREAKING CHANGES

- ea51b0b napi: [**BREAKING**] Standardize function naming with sync suffixes (#15661) (Boshen)

### 🚀 Features

- 77efb76 parser: Improve error message for invalid switch clauses (#15728) (sapphi-red)
- 5691727 parser: Improve `import source` `from` error message (#15727) (sapphi-red)
- b7404bc parser: Improve error message for missing function body (#15726) (sapphi-red)
- 71c2fb0 parser: Improve error message when JSX is found while not enabled (#15725) (sapphi-red)
- 56e7e44 minifier: Disable removal of unnecessary `use strict` directives for DCE (#15691) (sapphi-red)
- 8a61cfd allocator, ast: Introduce `UnstableAddress` trait (#15700) (overlookmotel)
- f5ce55a napi: Export all options using wildcard exports (Boshen)
- 68703b9 minifier: Rotate binary expressions to remove parentheses (#15473) (sapphi-red)

### 🐛 Bug Fixes

- c023ba6 semantic: Do not duplicate statements in temp `Vec` when binding `TSModuleDeclaration`s (#15724) (overlookmotel)
- d60ca81 parser: Reject `import something 'source'` (#15746) (sapphi-red)
- e0728fa ast: Exclude comment end position from `is_inside_comment` check (#15753) (camc314)
- 9f54a36 semantic: Error on `\00` in strict mode (#15743) (sapphi-red)
- 440a977 ast: Include rest properties when using `get_binding_identifiers` (#15710) (camc314)

### ⚡ Performance

- 1f09d3c parser: Faster checking for invalid modifiers (#15717) (overlookmotel)
- d8d4e31 ast: Use loop instead of recursion in `TSModuleDeclarationBody::as_module_block_mut` (#15713) (overlookmotel)

### 📚 Documentation

- e033d50 ast: Clarify behavior of `TSModuleDeclaration::has_use_strict_directive` (#15730) (overlookmotel)
- 9eda70f allocator: Improve docs for `Address` methods (#15697) (overlookmotel)
overlookmotel pushed a commit that referenced this pull request Nov 17, 2025
### 💥 BREAKING CHANGES

- ea51b0b napi: [**BREAKING**] Standardize function naming with sync
suffixes (#15661) (Boshen)

### 🚀 Features

- 77efb76 parser: Improve error message for invalid switch clauses
(#15728) (sapphi-red)
- 5691727 parser: Improve `import source` `from` error message (#15727)
(sapphi-red)
- b7404bc parser: Improve error message for missing function body
(#15726) (sapphi-red)
- 71c2fb0 parser: Improve error message when JSX is found while not
enabled (#15725) (sapphi-red)
- 56e7e44 minifier: Disable removal of unnecessary `use strict`
directives for DCE (#15691) (sapphi-red)
- 8a61cfd allocator, ast: Introduce `UnstableAddress` trait (#15700)
(overlookmotel)
- f5ce55a napi: Export all options using wildcard exports (Boshen)
- 68703b9 minifier: Rotate binary expressions to remove parentheses
(#15473) (sapphi-red)

### 🐛 Bug Fixes

- c023ba6 semantic: Do not duplicate statements in temp `Vec` when
binding `TSModuleDeclaration`s (#15724) (overlookmotel)
- d60ca81 parser: Reject `import something 'source'` (#15746)
(sapphi-red)
- e0728fa ast: Exclude comment end position from `is_inside_comment`
check (#15753) (camc314)
- 9f54a36 semantic: Error on `\00` in strict mode (#15743) (sapphi-red)
- 440a977 ast: Include rest properties when using
`get_binding_identifiers` (#15710) (camc314)

### ⚡ Performance

- 1f09d3c parser: Faster checking for invalid modifiers (#15717)
(overlookmotel)
- d8d4e31 ast: Use loop instead of recursion in
`TSModuleDeclarationBody::as_module_block_mut` (#15713) (overlookmotel)

### 📚 Documentation

- e033d50 ast: Clarify behavior of
`TSModuleDeclaration::has_use_strict_directive` (#15730) (overlookmotel)
- 9eda70f allocator: Improve docs for `Address` methods (#15697)
(overlookmotel)
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
`Modifiers` contains 2 different representations of the modifiers list:

* `ModifierFlags` bitflags
* `Vec<Modifier>`

When checking modifiers, use `ModifierFlags` (which is really cheap), rather than iterating through the `Vec<Modifier>` (more expensive).

Only if the first check fails, then loop through the `Vec` to get the spans of the invalid modifiers, and generate diagnostics.

Because invalid modifiers are rare, move the logic for looping through the `Vec` into a `#[cold]` `#[inline(never)]` function. This should make it possible to inline `verify_modifiers` into all the call sites.

Produces a small perf improvement on parser benchmarks (+0.1% - +0.2%).
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
### 💥 BREAKING CHANGES

- ea51b0b napi: [**BREAKING**] Standardize function naming with sync
suffixes (oxc-project#15661) (Boshen)

### 🚀 Features

- 77efb76 parser: Improve error message for invalid switch clauses
(oxc-project#15728) (sapphi-red)
- 5691727 parser: Improve `import source` `from` error message (oxc-project#15727)
(sapphi-red)
- b7404bc parser: Improve error message for missing function body
(oxc-project#15726) (sapphi-red)
- 71c2fb0 parser: Improve error message when JSX is found while not
enabled (oxc-project#15725) (sapphi-red)
- 56e7e44 minifier: Disable removal of unnecessary `use strict`
directives for DCE (oxc-project#15691) (sapphi-red)
- 8a61cfd allocator, ast: Introduce `UnstableAddress` trait (oxc-project#15700)
(overlookmotel)
- f5ce55a napi: Export all options using wildcard exports (Boshen)
- 68703b9 minifier: Rotate binary expressions to remove parentheses
(oxc-project#15473) (sapphi-red)

### 🐛 Bug Fixes

- c023ba6 semantic: Do not duplicate statements in temp `Vec` when
binding `TSModuleDeclaration`s (oxc-project#15724) (overlookmotel)
- d60ca81 parser: Reject `import something 'source'` (oxc-project#15746)
(sapphi-red)
- e0728fa ast: Exclude comment end position from `is_inside_comment`
check (oxc-project#15753) (camc314)
- 9f54a36 semantic: Error on `\00` in strict mode (oxc-project#15743) (sapphi-red)
- 440a977 ast: Include rest properties when using
`get_binding_identifiers` (oxc-project#15710) (camc314)

### ⚡ Performance

- 1f09d3c parser: Faster checking for invalid modifiers (oxc-project#15717)
(overlookmotel)
- d8d4e31 ast: Use loop instead of recursion in
`TSModuleDeclarationBody::as_module_block_mut` (oxc-project#15713) (overlookmotel)

### 📚 Documentation

- e033d50 ast: Clarify behavior of
`TSModuleDeclaration::has_use_strict_directive` (oxc-project#15730) (overlookmotel)
- 9eda70f allocator: Improve docs for `Address` methods (oxc-project#15697)
(overlookmotel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-parser Area - Parser 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