GeezerVison is showing github.com — perf(javascript): rebuild an evaluated node instead of copying the tree by alexander-akait · Pull Request #23259 · webpack/webpack
Conversation
alexander-akait
commented
Nov 11, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
Stacked on #23257. An evaluated expression pinned the tree it came from, so every parse that evaluated anything copied the tree's columns when the parse ended: 2,244 of 3,080 parses in a lib/ build, 75.1 MB of copies.
Before:
// BasicEvaluatedExpression#setNode
// pinned, so the node stays readable once the tree is released
this._source = tree.pinSource();
this._expression = node;
After:
// BasicEvaluatedExpression#setNode
this._source = tree.evaluationSource(node);
this._expression = node;
this._start = tree.start(node); // `range` reads these, never the columns
this._end = tree.end(node);
- A text parse registers a rebuild callback that parses the same text with the same options and gives the same node ids.
- At the end of a parse, a tree with no lazy objects and no pinned reader is marked
released instead of being copied.
- A node read after release parses the text again once; later reads reuse that rebuilt tree. In both
lib/ builds no node was read after release.
- An AST-built tree (custom
parse, the evaluate cache) and a node appended after the parse still pin and copy as before.
lib/ build, medians of 5 alternating runs on a loaded machine; time differences are within noise, output hashes are identical to main:
| Mode |
Column copies on release |
Build |
Parse |
Heap after seal |
| development |
75.1 MB (2,244 parses) → 0 |
4,864 → 4,790 ms |
2,102 → 2,077 ms |
170.9 → 170.9 MB |
| production |
→ 0 |
68,022 → 66,820 ms |
2,400 → 2,406 ms |
262.1 → 262.1 MB |
The copies were short-lived, so the heap after seal does not move; the gain is allocation during the parse.
What kind of change does this PR introduce?
perf
Did you add tests for your changes?
Yes: test/unitCases/javascript/evaluation-after-parse.unittest.js reads range and expression after release (member, template literal, nested call, conditional) against acorn's node, covers the AST-built tree that still copies, an appended node that stays pinned, and a rebuild that runs once.
Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Claude Code wrote the changes and measurements under my direction; I reviewed them.
🤖 Generated with Claude Code
https://claude.ai/code/session_013FhutRENJSfqFqSYN8hkt3
Summary by CodeRabbit
- Bug Fixes
- JavaScript expression details, including source ranges and nested expression data, remain available after parsing and when the syntax tree is released or reused.
- Repeated access to expression details now returns consistent results, including when the syntax tree is rebuilt.
Sorry, something went wrong.
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.
`BasicEvaluatedExpression#setNode` pinned the tree's source, so a release
copied every column for 2,244 of 3,080 parses of `lib` (75.1 MB). An
evaluation now keeps its node's offsets and, for a tree parsed from text,
an unpinned source: a read after the release parses the same text again
into the same node ids. Trees built from an AST and nodes appended after
the parse stay pinned.
Claude-Session: https://claude.ai/code/session_013FhutRENJSfqFqSYN8hkt3
coderabbitai
Bot
commented
Nov 11, 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
-
JavaScript parsing now registers callbacks that can rebuild released syntax trees. Lazy evaluation sources use those callbacks to reconstruct node data on first access. Node-backed expressions save their source offsets and expose node IDs only while their source remains unreleased.
Changes: Lazy evaluation-source lifecycle
| Layer / File(s) |
Summary |
Register syntax-tree rebuilds lib/javascript/JavascriptParser.js, lib/javascript/syntax-parser.js |
Direct source parsing registers a callback that reparses captured text with the current sourceType and importPhases. The tree stores the callback and node count, and clears the callback when released or reset. |
Rebuild released evaluation sources lib/javascript/syntax-parser.js, test/unitCases/javascript/evaluation-after-parse.unittest.js |
Evaluation sources use the rebuild callback for nodes within the recorded node count and pin the source for other nodes. A released source is rebuilt on its first lazy read, and the rebuilt source is cached. Tests cover pinning, release, and cached reads. |
Retain node-backed expression data lib/javascript/BasicEvaluatedExpression.js, test/unitCases/javascript/evaluation-after-parse.unittest.js |
Node-backed expressions save their start and end offsets and use evaluation sources instead of pinning. Tests check ranges, expression nodes, AST shapes, and expression data after parsing and tree reuse. |
Possibly related PRs
- webpack/webpack#23256: Converts parser hooks to node IDs and adds
BasicEvaluatedExpression.expressionNode; this PR extends the node-backed evaluation contract to reads after source release.
- webpack/webpack#23073: Introduces direct syntax-tree parsing in
JavascriptParser; this PR uses that parsing path to register rebuild callbacks.
Suggested labels: area: build-perf
Suggested reviewers: bjohansebas, avivkeller
Change: Refactor
Merge Risk: Minimal · up to ad336
-
This change avoids copying syntax-tree columns when a tree is released by rebuilding it on demand. No concrete merge-blocking risk was identified, and tests cover the rebuild, pinned-source and AST-built paths.
Pre-merge checks: 3 · 1
-
Failed checks: 1 inconclusive
| Check name |
Status |
Explanation |
Resolution |
| Title check |
 |
The title uses valid Conventional Commit syntax with the allowed type perf and scope javascript. The branch prefix is not provided, so the required type-prefix match cannot be verified. |
Provide the branch name or its prefix, and confirm that it uses the perf prefix. |
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. |
- 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 0dfac05 and ad336f9.
Files ignored due to path filters: 1
-
types.d.ts is excluded by !types.d.ts
Files selected for processing: 4
-
lib/javascript/BasicEvaluatedExpression.js
lib/javascript/JavascriptParser.js
lib/javascript/syntax-parser.js
test/unitCases/javascript/evaluation-after-parse.unittest.js
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Reports for ad336f9, 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@23259
yarn add -D webpack@https://pkg.pr.new/webpack@23259
pnpm add -D webpack@https://pkg.pr.new/webpack@23259
From Preview package run #12659.
Generated code size
Comparing base (0dfac05) to head (ad336f9). Merging this pull request will not change the code webpack generates.
| What moved |
Tests |
Assets |
Gzip |
Raw |
Test edit |
| Changed, test untouched |
0 |
0 |
— |
— |
— |
| Changed, test edited |
0 |
0 |
— |
— |
— |
| New |
0 |
0 |
— |
— |
— |
| Deleted |
0 |
0 |
— |
— |
— |
| Unchanged |
— |
10373 |
— |
— |
— |
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 changed size.
No runtime gained or lost a runtime module.
Built test/configCases with the defaults a user gets, and the apps in test/sizeCoreReports (apps/): 2508 test(s), 10373 asset(s), 108 emitted nothing.
From Generated code size run #7294.
Types Coverage
Typed lines: 99.70% (183624 of 184180)
| Kind |
Base |
Head |
Change |
any |
48 |
48 |
— |
unknown |
51 |
51 |
— |
object |
18 |
18 |
— |
Function |
1 |
1 |
— |
| untyped |
98 |
98 |
— |
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.
This pull request adds or removes no escape hatch, any or untyped identifier.
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/module/NormalModule.js |
99.55% |
4 |
|
|
|
9 |
lib/javascript/syntax-parser.js |
100.00% |
|
11 |
|
|
|
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.35% |
|
|
|
|
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/javascript/JavascriptParser.js |
100.00% |
|
|
1 |
|
2 |
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 #3544.
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 #788.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Merging this PR will regress 1 benchmark
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
⚠️ 6 benchmarks with a significant change ran on different hardware
Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
Learn more about Macro Runners
See affected benchmarks
ℹ️ 41 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
⚡ 5 improved benchmarks
❌ 1 regressed benchmark
✅ 345 untouched benchmarks
Performance Changes
|
Mode |
Benchmark |
BASE |
HEAD |
Efficiency |
| ❌ |
Memory |
benchmark "wasm-modules-async", scenario '{"name":"mode-development","mode":"development"}' |
393.8 KB |
497.7 KB |
-20.89% |
| ⚡ |
Memory |
benchmark "wasm-modules-sync", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
331.8 KB |
114.8 KB |
×2.9 |
| ⚡ |
Memory |
benchmark "concatenate-modules", scenario '{"name":"mode-production","mode":"production"}' |
3 MB |
2.1 MB |
+44.35% |
| ⚡ |
Memory |
benchmark "react", scenario '{"name":"mode-production","mode":"production"}' |
254.8 KB |
197.6 KB |
+28.97% |
| ⚡ |
Memory |
benchmark "concatenate-modules", scenario '{"name":"mode-development","mode":"development"}' |
5.1 MB |
4.2 MB |
+22.01% |
| ⚡ |
Memory |
benchmark "lodash", scenario '{"name":"mode-development","mode":"development"}' |
4 MB |
3.3 MB |
+20.76% |
Tip Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing perf/javascript-evaluation-ranges (ad336f9) with main (0dfac05)
|
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.
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.
|