Repository navigation
perf(parser): avoid rescanning tokens after successful lookahead - #1825
magic-akari wants to merge 2 commits into
Conversation
Looking past contextual keywords such as `async`, `static`, and `type` used to scan the following token twice whenever the prefix matched. Keep the scanned token and lexer state on a match. Restore the lexer on a mismatch or lexical error so parsing can retry at the same token.
Finish single-parameter async arrows in a separate function after the arrow token matches. This keeps parameter validation out of ordinary prefix expressions. Handle JSDoc type suffixes in a cold function and scan tuple identifiers into a local token while retaining the lexer checkpoint for recovery.
Deploying swc-next with
|
| Latest commit: |
9c45e36
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c1ad584e.swc-next.pages.dev |
| Branch Preview URL: | https://perf-parser-reuse-lookahead.swc-next.pages.dev |
Binary size diffLinux x64 GNU · release · uncompressed, stripped bindings. Merge:
|
Gungraun benchmark diffBase SHA: f6f4151 Values are shown as Download the raw Gungraun and Valgrind data (retained for 90 days). Callgrind metric changesCallgrind instruction counts (Ir) for the compare and base revisions. Values are shown as compare / base in K (1,000), truncated to whole thousands. Multi-part profiles use the part numbers from Gungraun and include an aggregated Total. New and Removed identify benchmarks that exist on only one side; the missing value is shown as a dash. Percentages are rounded to at most three decimal places. Lower is better: 🟢 improvement, 🔴 regression, ⚪ unchanged. Formatter
Generator
Minifier
Parser
Semantic
Transform
Type strip
Visit
Benchmark results |
JavaScript API Gungraun benchmark diffBase: Values are shown as Download the raw Gungraun and Valgrind data (retained for 90 days). Callgrind metric changesMedian instruction counts from three processes, shown as compare / base in K (1,000), truncated to whole thousands. Percentages are rounded to at most three decimal places. Lower is better: 🟢 improvement, 🔴 regression, ⚪ unchanged or overlapping ranges (inconclusive). JIT disabled (--jitless); predictable mode enabled (--predictable). Counts are not wall time. Exact counts, ranges and profiles are retained in artifacts. Generate
Lang
Parse
Source type
Walk
Benchmark resultsExact instruction counts: median (min–max).
|
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Motivation
When the parser recognizes constructs such as
async function, class static blocks, and TypeScriptexport typedeclarations, it can scan the same token twice. The lookahead reads the token to identify the construct, then rewinds the lexer. Advancing the parser reads the token and its leading trivia again.Changes
async x => xcase into separate helpers.