Skip to content

perf(parser): remove branch from parse_modifiers#20821

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/03-28-perf_parser_remove_branch_from_parse_modifiers_
Mar 29, 2026
Merged

perf(parser): remove branch from parse_modifiers#20821
graphite-app[bot] merged 1 commit intomainfrom
om/03-28-perf_parser_remove_branch_from_parse_modifiers_

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Mar 28, 2026

Small perf optimization.

Modifiers already encodes which modifiers have been seen, so there's no need to additionally track whether a static modifier has been seen or not in a separate variable.

Remove has_seen_static_modifier variable from parse_modifiers, and the unpredictable branch which updates it, and instead do the check only when it's needed in try_parse_modifier.

+0.1% improvement on some parser benchmarks, and CodSpeed doesn't take into account the cost of branch misprediction.

Copy link
Copy Markdown
Member Author

overlookmotel commented Mar 28, 2026


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.

Copy link
Copy Markdown
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 applies a small hot-path optimization in the parser’s modifier parsing by removing a dedicated has_seen_static_modifier tracking branch and relying on the existing ModifierKinds bitfield already stored in Modifiers.

Changes:

  • Remove has_seen_static_modifier from parse_modifiers.
  • Pass the already-seen ModifierKinds into try_parse_modifier and use it to detect repeated static.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 28, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing om/03-28-perf_parser_remove_branch_from_parse_modifiers_ (2e7e6bd) with main (eb02c88)2

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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

@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Mar 29, 2026
Copy link
Copy Markdown
Contributor

camc314 commented Mar 29, 2026

Merge activity

  • Mar 29, 3:31 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Mar 29, 3:40 PM UTC: The Graphite merge queue removed this pull request due to removal of a downstack PR #20820.
  • Mar 29, 3:40 PM UTC: camc314 added this pull request to the Graphite merge queue.
  • Mar 29, 3:41 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Mar 29, 3:41 PM UTC: The merge label '0-merge' was removed. This PR will no longer be merged by the Graphite merge queue
  • Mar 29, 3:41 PM UTC: camc314 added this pull request to the Graphite merge queue.
  • Mar 29, 4:19 PM UTC: The Graphite merge queue removed this pull request due to downstack failures on PR #20820.
  • Mar 29, 4:40 PM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Mar 29, 4:41 PM UTC: camc314 added this pull request to the Graphite merge queue.
  • Mar 29, 4:42 PM UTC: Merged by the Graphite merge queue.

@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 29, 2026
@graphite-app graphite-app bot force-pushed the om/03-28-perf_parser_reduce_kind_to_modifierkind_conversions_in_eat_modifiers_before_declaration_ branch from ebbdd03 to ccbd3e9 Compare March 29, 2026 15:42
graphite-app bot pushed a commit that referenced this pull request Mar 29, 2026
Small perf optimization.

`Modifiers` already encodes which modifiers have been seen, so there's no need to additionally track whether a `static` modifier has been seen or not in a separate variable.

Remove `has_seen_static_modifier` variable from `parse_modifiers`, and the unpredictable branch which updates it, and instead do the check only when it's needed in `try_parse_modifier`.

+0.1% improvement on some parser benchmarks, and CodSpeed doesn't take into account the cost of branch misprediction.
@graphite-app graphite-app bot force-pushed the om/03-28-perf_parser_remove_branch_from_parse_modifiers_ branch from 26f05f9 to b3ca6a4 Compare March 29, 2026 15:43
@camc314 camc314 force-pushed the om/03-28-perf_parser_reduce_kind_to_modifierkind_conversions_in_eat_modifiers_before_declaration_ branch from ccbd3e9 to eb02c88 Compare March 29, 2026 16:34
Base automatically changed from om/03-28-perf_parser_reduce_kind_to_modifierkind_conversions_in_eat_modifiers_before_declaration_ to main March 29, 2026 16:37
Small perf optimization.

`Modifiers` already encodes which modifiers have been seen, so there's no need to additionally track whether a `static` modifier has been seen or not in a separate variable.

Remove `has_seen_static_modifier` variable from `parse_modifiers`, and the unpredictable branch which updates it, and instead do the check only when it's needed in `try_parse_modifier`.

+0.1% improvement on some parser benchmarks, and CodSpeed doesn't take into account the cost of branch misprediction.
@graphite-app graphite-app bot force-pushed the om/03-28-perf_parser_remove_branch_from_parse_modifiers_ branch from b3ca6a4 to 2e7e6bd Compare March 29, 2026 16:38
@camc314 camc314 added the 0-merge Merge with Graphite Merge Queue label Mar 29, 2026
@graphite-app graphite-app bot merged commit 2e7e6bd into main Mar 29, 2026
35 checks passed
@graphite-app graphite-app bot deleted the om/03-28-perf_parser_remove_branch_from_parse_modifiers_ branch March 29, 2026 16:42
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 29, 2026
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.

3 participants