-
-
Notifications
You must be signed in to change notification settings - Fork 723
perf(parser): cache redundant token operations in hot paths #13775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this 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 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.
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
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