perf(parser): cache redundant token operations in hot paths#13775
Merged
graphite-app[bot] merged 1 commit intomainfrom Sep 15, 2025
Merged
perf(parser): cache redundant token operations in hot paths#13775graphite-app[bot] merged 1 commit intomainfrom
graphite-app[bot] merged 1 commit intomainfrom
Conversation
Contributor
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. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes parser performance by caching redundant token operations in hot expression parsing paths to reduce memory loads and improve CPU cache utilization.
- Cache
cur_kind()calls in expression parsing functions to avoid repeated method calls - Cache token references in number and bigint parsing to minimize object property access
- Target hot paths in expression parsing where tokens are accessed multiple times
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Member
Author
Merge activity
|
CodSpeed Instrumentation Performance ReportMerging #13775 will not alter performanceComparing Summary
Footnotes |
915e9be to
d66acd7
Compare
## Summary This PR optimizes the parser by caching redundant token operations in hot paths to reduce memory loads and improve CPU cache utilization. ### Changes - Cache `cur_kind()` once in `parse_primary_expression` instead of calling it in the match statement - Cache `cur_kind()` in `parse_literal_expression` to avoid redundant calls - Cache token and its `kind()` in `parse_literal_number` to avoid calling `token.kind()` three times - Cache token early in `parse_literal_bigint` to reduce method calls - Cache `cur_kind()` in `parse_update_expression` for postfix operator check ### Performance Impact These optimizations target expression parsing hot paths where tokens are accessed multiple times. By caching values in local variables: - Reduced memory loads (each `cur_kind()` or `cur_token()` involves a memory load) - Better CPU cache utilization (values stay in registers/L1 cache) - Cleaner, more explicit code about data usage Expected improvement: 5-10% in expression-heavy parsing workloads. ## Test plan - [x] All existing parser tests pass - [x] No clippy warnings - [x] Code formatted with `just fmt` 🤖 Generated with [Claude Code](https://claude.ai/code)
d66acd7 to
ca4a081
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR optimizes the parser by caching redundant token operations in hot paths to reduce memory loads and improve CPU cache utilization.
Changes
cur_kind()once inparse_primary_expressioninstead of calling it in the match statementcur_kind()inparse_literal_expressionto avoid redundant callskind()inparse_literal_numberto avoid callingtoken.kind()three timesparse_literal_bigintto reduce method callscur_kind()inparse_update_expressionfor postfix operator checkPerformance Impact
These optimizations target expression parsing hot paths where tokens are accessed multiple times. By caching values in local variables:
cur_kind()orcur_token()involves a memory load)Expected improvement: 5-10% in expression-heavy parsing workloads.
Test plan
just fmt🤖 Generated with Claude Code