GeezerVison is showing github.com — perf(javascript): walk statements and plain expressions of the syntax tree by id by alexander-akait · Pull Request #23242 · webpack/webpack
Conversation
alexander-akait
commented
Nov 9, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
Stacked on #23241, with #23238's three commits under it (this slice restores the tree in #23238's parse wrapper). Next slice of #23083: with the internal tree walk on, the walk reads node ids instead of objects where it can.
walkExpression(expression) {
const tree = this._tree;
if (tree !== undefined) {
const id = tree.nodeOf(expression); // a lazy object of this parse's tree
if (id !== 0) return this._walkExpressionNode(id);
}
this._walkExpressionObject(expression);
}
walkStatement and walkExpression move to the id walk whenever they get a lazy object of the tree, so every object walker still in place hands its children back to it: one implementation, no copy per walker.
- By id: statements and their hook,
if, return/throw, blocks, identifiers, literals, this, binary and logical expressions, arrays, templates, spreads, await. A hook gets the node's object only when it has a tap or interceptor (_callNode, _argumentOf).
isPure reads the tree in place instead of an EstreeView.
- Calls, members, functions, classes, patterns and the pre-walks stay object walks; the next slices port them.
Share of nodes that get an object with the tree walk on (development builds):
| build |
#23241 |
here |
| lodash-es (44,417 nodes) |
98.7% |
96.7% |
webpack's lib/ (2.23M nodes) |
93.1% |
89.4% |
Output stays byte-identical (same hashes on both builds). Calls and members still build most objects, so the switch stays off; off, the walk pays one undefined check per statement and expression.
All 1148 parsing tests of TestCases and ConfigTestCases pass with the switch forced on locally.
What kind of change does this PR introduce?
perf
Did you add tests for your changes?
Yes, test/configCases/parsing/walk-syntax-tree now walks each type this slice reads by id: if/else if, return, throw, unreachable statements, spreads, templates, binary, logical, typeof, conditionals and this.
Does this PR introduce a breaking change?
No; the switch is internal and off.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
AI (Claude Code) was used, directed and reviewed by the author, to port this slice of #23083, find which code builds objects (sampled stacks), write the test and compare builds.
Generated by Claude Code
Summary by CodeRabbit
- Improvements
- Improved JavaScript parsing across nested parses and a wider range of syntax, including spread expressions, template literals, and boolean expressions.
- Preserved purity checks and annotation handling during parsing, including for nested expressions.
- Expanded coverage for imported values, function behavior, and error cases.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
changeset-bot
Bot
commented
Nov 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Nov 9, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review.
Walkthrough
-
JavascriptParser now walks parser-generated syntax trees by node ID when available and retains object-based walking as a fallback. Hook dispatch converts IDs to ESTree objects when needed. Purity queries can read from the active tree. Parsing tests cover tree walking, purity checks, and nested parsing.
Changes: Syntax-tree walking
| Layer / File(s) |
Summary |
Tree lifecycle and entry point lib/javascript/JavascriptParser.js |
The parser saves and restores tree state around parsing, installs the parsed tree, and walks the program body by node ID when a tree is available. |
ID-based walking, hooks, and purity lib/javascript/JavascriptParser.js |
Statement and expression walkers traverse tree nodes by ID. Hook dispatch resolves IDs to ESTree objects when needed. Purity queries use the active tree and preserve annotation-comment handling. |
Tree-walking behavior checks test/configCases/parsing/walk-syntax-tree/index.js, test/configCases/parsing/walk-syntax-tree/walked.js, test/configCases/parsing/walk-syntax-tree/webpack.config.js |
The fixture and assertions cover added syntax forms, control flow, receiver behavior, and nested parsing. The config checks purity before and after nested parsing and updates the expected walked count to six. |
Possibly related PRs
- webpack/webpack#23073: Adds
parseProgram and syntax-tree output used by this ID-based walking path.
- webpack/webpack#23241: Adds the lazy syntax-tree parse path that this PR extends with ID-based statement and expression walking.
- webpack/webpack#23220: Changes
parseProgram and syntax-tree support used by this parser path.
Suggested labels: area: build-perf
Change: Refactor
Merge Risk: Minimal · up to 1b95c
-
This change moves statement and expression walking to node IDs and keeps the object-based walk as a fallback. The switch stays off, so default behavior is unchanged. No concrete merge-blocking risk was found.
Pre-merge checks: 3 · 1
-
Failed checks: 1 inconclusive
| Check name |
Status |
Explanation |
Resolution |
| Title check |
 |
The title uses the required conventional-commit form, and its perf type and subject describe the ID-based syntax-tree walking change. The branch prefix is not provided, so the required type-to-branc… |
Provide the branch name or confirm that its prefix is perf. |
Passed checks: 3 passed
-
| Check name |
Status |
Explanation |
| Description Check |
 |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Linked Issues check |
 |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
 |
Check skipped because no linked issues were found for this pull request. |
Full details: Title check
-
Explanation
The title uses the required conventional-commit form, and its perf type and subject describe the ID-based syntax-tree walking change. The branch prefix is not provided, so the required type-to-branch-prefix match cannot be verified.
Resolution
Provide the branch name or confirm that its prefix is perf.
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
-
Recent review info
-
Run configuration
-
Commits
-
Reviewing files that changed from the base of the PR and between b979839 and 1b95c35.
Files selected for processing: 4
-
lib/javascript/JavascriptParser.js
test/configCases/parsing/walk-syntax-tree/index.js
test/configCases/parsing/walk-syntax-tree/walked.js
test/configCases/parsing/walk-syntax-tree/webpack.config.js
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
… tree by id
With the tree walk on, `walkStatement` and `walkExpression` move to the
node's id whenever they are handed a lazy object of the tree. Statements,
`if`, `return`/`throw`, blocks, identifiers, literals, `this`, binary and
logical expressions, arrays, templates, spreads and `await` are walked by
id, so a hook gets an object only when it has a tap. `isPure` reads the
tree in place. Every other type is still walked as its object.
Claude-Session: https://claude.ai/code/session_013FhutRENJSfqFqSYN8hkt3
|
Reports for 1b95c35, computed by this pull request's own code. Each section updates when its workflow finishes.
Preview package
This PR is packaged and the instant preview of its latest commit is available.
Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@23242
yarn add -D webpack@https://pkg.pr.new/webpack@23242
pnpm add -D webpack@https://pkg.pr.new/webpack@23242
From Preview package run #12594.
Generated code size
Comparing base (8efebba) to head (1b95c35). Merging this pull request moves 1 asset(s) whose tests it edits too.
| What moved |
Tests |
Assets |
Gzip |
Raw |
Test edit |
| Changed, test untouched |
0 |
0 |
— |
— |
— |
| Changed, test edited |
1 |
1 |
🔴 ↑ +162 B |
🔴 ↑ +387 B |
🔴 ↑ +978 B |
| New |
0 |
0 |
— |
— |
— |
| Deleted |
0 |
0 |
— |
— |
— |
| Unchanged |
— |
10350 |
— |
— |
— |
Read Changed, test untouched first: the test is byte-identical on both sides, so webpack generated the difference. Changed, test edited moved partly because the test did — Test edit is how many bytes the test gained, and a bundle that grew by less is not a regression. New and Deleted are whole files, not deltas — a new asset was created, not grown, so it reads gray (⚪ added) — and adding tests cannot bury a real change. Gzip decides, because that is what users download; raw is the tiebreak, and brotli and zstd are per asset below.
Sample apps
No sample app changed size.
26 unchanged app(s)
| App |
Gzip |
Gzip change |
Raw |
Raw change |
library amd |
1.38 KiB |
— |
2.68 KiB |
— |
library amd-require |
1.38 KiB |
— |
2.67 KiB |
— |
library assign |
1.38 KiB |
— |
2.67 KiB |
— |
library assign-properties |
1.42 KiB |
— |
2.80 KiB |
— |
library commonjs |
1.38 KiB |
— |
2.66 KiB |
— |
library commonjs-module |
1.38 KiB |
— |
2.67 KiB |
— |
library commonjs-static |
1.55 KiB |
— |
3.54 KiB |
— |
library commonjs2 |
1.38 KiB |
— |
2.67 KiB |
— |
library global |
1.38 KiB |
— |
2.66 KiB |
— |
library jsonp |
1.37 KiB |
— |
2.66 KiB |
— |
library module |
1.21 KiB |
— |
2.35 KiB |
— |
library self |
1.38 KiB |
— |
2.66 KiB |
— |
library system |
1.41 KiB |
— |
2.73 KiB |
— |
library this |
1.38 KiB |
— |
2.66 KiB |
— |
library umd |
1.44 KiB |
— |
2.86 KiB |
— |
library umd2 |
1.44 KiB |
— |
2.86 KiB |
— |
library var |
1.38 KiB |
— |
2.67 KiB |
— |
library window |
1.38 KiB |
— |
2.66 KiB |
— |
node-ssr |
96.36 KiB |
— |
371.30 KiB |
— |
node-ssr-esm |
96.61 KiB |
— |
372.00 KiB |
— |
react-100 |
32.17 KiB |
— |
150.55 KiB |
— |
react-1k |
73.34 KiB |
— |
907.38 KiB |
— |
react-1k-esm |
72.54 KiB |
— |
906.44 KiB |
— |
react-5k |
191.49 KiB |
— |
4.08 MiB |
— |
webworker |
36.60 KiB |
— |
95.02 KiB |
— |
webworker-esm |
35.67 KiB |
— |
94.21 KiB |
— |
No asset with an untouched test changed size — every change below comes with a test this pull request edited.
1 asset(s) changed size, test edited
|
Asset |
Before |
After |
Change |
Gzip (9) |
Brotli (11) |
Zstd (19) |
Test edit (per test) |
| 🔴 ↑ |
parsing/walk-syntax-tree bundle0.js |
1.65 KiB |
2.03 KiB |
+387 B (+22.93%) |
+162 B (+21.49%) |
+151 B (+22.47%) |
+156 B (+20.42%) |
+978 B |
No runtime gained or lost a runtime module.
Built test/configCases with the defaults a user gets, and the apps in test/sizeCoreReports (apps/): 2496 test(s), 10351 asset(s), 107 emitted nothing.
From Generated code size run #7229.
Types Coverage
Typed lines: 99.69% (181027 of 181583)
| Kind |
Base |
Head |
Change |
any |
48 |
49 |
🔴 +1 |
unknown |
50 |
51 |
🔴 +1 |
object |
18 |
18 |
— |
Function |
1 |
1 |
— |
| untyped |
98 |
107 |
🔴 +9 |
any counts EXPECTED_ANY, a written any and the any TypeScript infers where no type is written, such as const map = new Map() or const list = []. unknown counts a written unknown; ThrownValue, the unknown a throw or a rejected promise hands on, is left out. object counts EXPECTED_OBJECT and Object, Function counts EXPECTED_FUNCTION. Untyped counts the identifiers whose type is or holds any, wherever it comes from; the any TypeScript's built-in lib and Node.js's @types/node write in their own signatures, such as the replacer of String#replace or a stream's chunk, is left out, and so is the open fallback beside declared fields, such as KnownBuildInfo & Record<string, any>, though reading a key no field declares is counted.
Changed by this pull request
| File |
Typed lines |
any |
unknown |
object |
Function |
untyped |
lib/javascript/JavascriptParser.js |
100.00% |
1 (🔴 +1) |
1 (🔴 +1) |
1 |
|
11 (🔴 +9) |
Where this pull request adds them, in every column it grows
lib/javascript/JavascriptParser.js:1983 untyped factory: ((key: any, hook: PathTaps<[number], boolean | void> & SyncBailHook<[MaybeNamedClassDeclaration | Ma…
lib/javascript/JavascriptParser.js:1995 untyped factory: ((key: any, hook: PathTaps<[number], boolean | void> & SyncBailHook<[MaybeNamedClassDeclaration | Ma…
lib/javascript/JavascriptParser.js:3789 untyped _callNode: <R>(hook: SyncBailHook<[any], R, UnsetAdditionalOptions>, id: number) => R | undefined
lib/javascript/JavascriptParser.js:3868 untyped _callNode: <R>(hook: SyncBailHook<[any], R, UnsetAdditionalOptions>, id: number) => R | undefined
lib/javascript/JavascriptParser.js:3885 untyped _callNode: <R>(hook: SyncBailHook<[any], R, UnsetAdditionalOptions>, id: number) => R | undefined
lib/javascript/JavascriptParser.js:3888 untyped _callNode: <R>(hook: SyncBailHook<[any], R, UnsetAdditionalOptions>, id: number) => R | undefined
lib/javascript/JavascriptParser.js:3959 untyped _callNode: <R>(hook: SyncBailHook<[any], R, UnsetAdditionalOptions>, id: number) => R | undefined
lib/javascript/JavascriptParser.js:3965 untyped _callNode: <R>(hook: SyncBailHook<[any], R, UnsetAdditionalOptions>, id: number) => R | undefined
lib/javascript/JavascriptParser.js:3985 untyped _callNode: <R>(hook: SyncBailHook<[any], R, UnsetAdditionalOptions>, id: number) => R | undefined
lib/javascript/JavascriptParser.js:3998 any (EXPECTED_ANY)
lib/javascript/JavascriptParser.js:4002 untyped _callNode: <R>(hook: SyncBailHook<[any], R, UnsetAdditionalOptions>, id: number) => R | undefined
lib/javascript/JavascriptParser.js:4002 untyped hook: SyncBailHook<[any], R, UnsetAdditionalOptions>
lib/javascript/JavascriptParser.js:6608 unknown
What the files this pull request changes still have
lib/javascript/JavascriptParser.js:495 object (EXPECTED_OBJECT)
55 file(s) in lib/, hot/, declarations/ and bin/ still have an escape hatch, `any` or untyped identifiers
| File |
Typed lines |
any |
unknown |
object |
Function |
untyped |
lib/Compilation.js |
99.75% |
5 |
|
|
|
15 |
lib/logging/createConsoleLogger.js |
99.00% |
|
|
|
|
15 |
lib/module/NormalModuleFactory.js |
99.41% |
|
|
|
|
15 |
declarations/WebpackOptions.ts |
100.00% |
12 |
|
|
|
2 |
lib/javascript/JavascriptParser.js |
100.00% |
1 (🔴 +1) |
1 (🔴 +1) |
1 |
|
11 (🔴 +9) |
lib/module/NormalModule.js |
99.55% |
4 |
|
|
|
9 |
lib/javascript/syntax-parser.js |
100.00% |
|
10 |
|
|
|
lib/asset/AssetModulesPlugin.js |
99.38% |
|
|
|
|
9 |
lib/Compiler.js |
100.00% |
2 |
4 |
|
|
|
lib/javascript/syntax-printer.js |
100.00% |
|
1 |
5 |
|
|
lib/loaders/LoaderPlugin.js |
99.42% |
|
|
|
|
6 |
lib/util/SourceProcessor.js |
100.00% |
|
6 |
|
|
|
lib/dependencies/amd/AMDPlugin.js |
99.31% |
|
|
|
|
5 |
lib/dependencies/amd/AMDRuntimeModules.js |
95.45% |
|
|
|
|
4 |
lib/javascript/JavascriptModulesPlugin.js |
100.00% |
|
|
|
|
4 |
lib/loaders/LoaderOptionsPlugin.js |
100.00% |
4 |
|
|
|
|
lib/module/Module.js |
100.00% |
4 |
|
|
|
|
lib/resolve/getResolveOptionsKey.js |
100.00% |
|
4 |
|
|
|
lib/serialization/ObjectMiddleware.js |
100.00% |
|
|
4 |
|
|
lib/util/SortableSet.js |
100.00% |
|
4 |
|
|
|
lib/config/normalization.js |
99.57% |
|
|
|
|
3 |
lib/css/syntax-parser.js |
100.00% |
|
3 |
|
|
|
lib/hmr/HotModuleReplacement.runtime.js |
100.00% |
|
2 |
1 |
|
|
lib/html/syntax-parser.js |
100.00% |
|
3 |
|
|
|
lib/stats/StatsFactory.js |
100.00% |
2 |
|
1 |
|
|
lib/config/defineConfig.js |
100.00% |
2 |
|
|
|
|
lib/css/syntax.js |
100.00% |
|
2 |
|
|
|
lib/define/DefinePlugin.js |
100.00% |
|
1 |
|
1 |
|
lib/hmr/HotModuleReplacementPlugin.js |
100.00% |
|
1 |
|
|
1 |
lib/hmr/JavascriptHotModuleReplacement.runtime.js |
100.00% |
|
|
2 |
|
|
lib/html/syntax.js |
100.00% |
|
2 |
|
|
|
lib/index.js |
100.00% |
2 |
|
|
|
|
lib/loaders/LoaderRunner.js |
100.00% |
2 |
|
|
|
|
lib/module/Parser.js |
100.00% |
2 |
|
|
|
|
lib/node/nodeConsole.js |
100.00% |
|
2 |
|
|
|
lib/rules/BasicEffectRulePlugin.js |
93.75% |
|
|
|
|
2 |
lib/rules/UseEffectRulePlugin.js |
99.06% |
|
|
|
|
2 |
lib/util/cleverMerge.js |
100.00% |
|
|
2 |
|
|
lib/util/implicitTypeLoaderFallback.js |
100.00% |
|
|
|
|
2 |
lib/config/WebpackOptionsApply.js |
100.00% |
|
|
|
|
1 |
lib/config/cli.js |
100.00% |
1 |
|
|
|
|
lib/dependencies/import/ImportParserPlugin.js |
100.00% |
|
1 |
|
|
|
lib/dll/DllReferencePlugin.js |
100.00% |
1 |
|
|
|
|
lib/errors/JSONParseError.js |
100.00% |
|
|
|
|
1 |
lib/graph/ModuleGraph.js |
100.00% |
1 |
|
|
|
|
lib/javascript/syntax.js |
100.00% |
|
1 |
|
|
|
lib/logging/Logger.js |
100.00% |
1 |
|
|
|
|
lib/output/ManifestPlugin.js |
100.00% |
1 |
|
|
|
|
lib/serialization/types.js |
100.00% |
|
|
1 |
|
|
lib/stats/DefaultStatsFactoryPlugin.js |
100.00% |
|
1 |
|
|
|
lib/stats/StatsPrinter.js |
100.00% |
1 |
|
|
|
|
lib/template/Template.js |
100.00% |
1 |
|
|
|
|
lib/util/magicComment.js |
100.00% |
|
1 |
|
|
|
lib/util/makeSerializable.js |
100.00% |
|
|
1 |
|
|
lib/util/terminalColors.js |
100.00% |
|
1 |
|
|
|
From Types Coverage run #3492.
Module loading
How many files a fresh Node.js process loads (require or import) to do each thing below; a change from the pull request's base is marked 🔴 when it grew and 🟢 when it shrank. Every file is startup time, so fewer is better. webpack files are this package's own (lib/, hot/); node_modules files are its dependencies'.
| What the process does |
webpack files |
node_modules files |
require("webpack") |
2 |
0 |
import "webpack" |
2 |
0 |
| JavaScript syntax |
11 |
0 |
| CSS syntax |
12 |
0 |
| HTML syntax |
11 |
0 |
| XML syntax |
11 |
0 |
| JavaScript minifier |
12 |
0 |
| CSS minifier |
14 |
0 |
| HTML minifier |
19 |
0 |
| XML minifier |
14 |
0 |
| JSON minifier |
1 |
0 |
| development build |
439 |
103 |
| production build |
446 |
133 |
| watch with HMR, one rebuild |
449 |
110 |
From Module loading run #736.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
❌ Patch coverage is 91.93548% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.98%. Comparing base (8efebba) to head (1b95c35).
Additional details and impacted files
@@ Coverage Diff @@
## main #23242 +/- ##
==========================================
- Coverage 96.99% 96.98% -0.02%
==========================================
Files 804 804
Lines 142286 142464 +178
Branches 49552 49611 +59
==========================================
+ Hits 138011 138167 +156
- Misses 4275 4297 +22
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Merging this PR will improve performance by 58.22%
2 warnings, 1 note
⚠️ 117 benchmarks are dominated by system calls
System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.
Learn more about system calls
See affected benchmarks
⚠️ 1 benchmark with a significant change ran on different hardware
Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.
Learn more about Macro Runners
See affected benchmarks
ℹ️ 39 benchmarks have no flamegraph
The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.
See affected benchmarks
⚡ 3 improved benchmarks
✅ 348 untouched benchmarks
Performance Changes
Tip Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.
Comparing perf/javascript-walk-statements-by-id (1b95c35) with main (8efebba)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 10, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
area: build-perf
Build time and memory of webpack itself
area: parser
JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies)
area: types
types.d.ts, JSDoc annotations, hand-maintained declarations
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|