Visitar URL original
perf(javascript): trim walker allocations by alexander-akait · Pull Request #21668 · webpack/webpack · GitHub
Skip to content

perf(javascript): trim walker allocations - #21668

Merged
alexander-akait merged 1 commit into
perf/js-parser-own-lazy-pathfrom
perf/js-parser-allocations
Sep 6, 2026
Merged

alexander-akait merged 1 commit into
perf/js-parser-own-lazy-pathfrom
perf/js-parser-allocations

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Summary

Final PR of the stack (depends on #21667; review shows only its own commit). Removes per-node allocations in JavascriptParser's walk phase: one-argument fast dispatch for per-identifier hook calls (drops a rest array + spread on ~422K calls per corpus pass), closure-free scope entry/exit for the internal block/function scope walks (~67K closures), guard-branch closures only when a guard frame exists, and an inlined Identifier-assignment pattern path. Measured on a 5-library corpus (alternating A/B CPU profiles): total sampled time −6%, GC time −11%, walkExpression self time −14%; public parser.hooks / in*Scope / callHooksFor* APIs unchanged.

What kind of change does this PR introduce?

perf

Did you add tests for your changes?

Yes — test/StackedMap.unittest.js gains stale-scope-view semantics tests; walker behavior is covered by the existing parser unit and integration suites (all green).

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

This PR was developed with Claude (AI assistant) under human direction: it performed the analysis, implementation, differential verification against acorn, and measurements; the requester reviewed and directed the work.


Generated by Claude Code

@changeset-bot

changeset-bot Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 526dd76

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 1 package
Name Type
webpack Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 40e82a9f-0eb1-4a22-9ccc-8a799ef5939e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies) label Aug 10, 2026
@alexander-akait
alexander-akait force-pushed the perf/js-parser-own-lazy-path branch from 8a23160 to 3a62192 Compare August 11, 2026 08:33
@alexander-akait
alexander-akait force-pushed the perf/js-parser-allocations branch from 6985278 to ef91be4 Compare August 11, 2026 08:33
@alexander-akait
alexander-akait force-pushed the perf/js-parser-own-lazy-path branch from 3a62192 to e90af84 Compare August 11, 2026 08:43
@alexander-akait
alexander-akait force-pushed the perf/js-parser-allocations branch from ef91be4 to c5c40a4 Compare August 11, 2026 08:43
@alexander-akait
alexander-akait force-pushed the perf/js-parser-own-lazy-path branch from e90af84 to 1a633dc Compare August 11, 2026 09:43
@alexander-akait
alexander-akait force-pushed the perf/js-parser-allocations branch from c5c40a4 to b53e3c0 Compare August 11, 2026 09:43
@alexander-akait
alexander-akait force-pushed the perf/js-parser-own-lazy-path branch from 1a633dc to 0c965a2 Compare August 27, 2026 18:24
@alexander-akait
alexander-akait force-pushed the perf/js-parser-allocations branch from b53e3c0 to f1a3da5 Compare August 27, 2026 18:24
- one-argument fast dispatch for per-identifier hook calls (no rest array
  + spread per identifier)
- closure-free scope entry/exit for the internal block/function scope walks
- guard-branch closures only allocated when a guard frame exists
- inline the Identifier left side of assignments past enterPattern
- pin StackedMap stale-view semantics with unit tests
@alexander-akait
alexander-akait force-pushed the perf/js-parser-own-lazy-path branch from 0c965a2 to 7174802 Compare September 6, 2026 11:59
@alexander-akait
alexander-akait force-pushed the perf/js-parser-allocations branch from f1a3da5 to 526dd76 Compare September 6, 2026 11:59
@alexander-akait
alexander-akait merged commit 44a0897 into perf/js-parser-own-lazy-path Sep 6, 2026
6 checks passed
@alexander-akait
alexander-akait deleted the perf/js-parser-allocations branch September 6, 2026 13:22
alexander-akait added a commit that referenced this pull request Sep 6, 2026
- one-argument fast dispatch for per-identifier hook calls (no rest array
  + spread per identifier)
- closure-free scope entry/exit for the internal block/function scope walks
- guard-branch closures only allocated when a guard frame exists
- inline the Identifier left side of assignments past enterPattern
- pin StackedMap stale-view semantics with unit tests
alexander-akait added a commit that referenced this pull request Sep 6, 2026
…21667)

* perf(javascript): own class bodies, methods and object property values

Land class declarations/expressions, class bodies, methods, fields, static
blocks, object methods, shorthand values and property clash checks on
single-shape nodes with the private-name bookkeeping owned, gated back to
acorn on plugin overrides. acorn's share of parse time drops to ~1% on
class- and module-heavy inputs, and many-small-module parsing gets ~4%
faster.

* perf(javascript): stop executing acorn code on the lazy parse path

Own the remaining utility layer — token predicates, scope accessors, error
raising, template-token dispatch, directive prologue, binding-list items,
catch params, the super/class/import atoms and the async/top-level-await
statement heads — as exact copies, so a lazy parse runs entirely in owned
code. A tripwire test instruments acorn's prototype and asserts zero calls;
what remains of the dependency is the class relationship, the token/context
and Unicode tables, and cold fallbacks (using declarations, non-lazy modes,
plugin gates).

* fix(javascript): serialize parse-error locations in the persistent cache

Register a serializer for the parser's ParserPosition so modules carrying a
ModuleParseError stay serializable, restoring the acorn Position behavior
(deserializes to a plain line/column object).

* perf(javascript): trim walker allocations (#21668)

- one-argument fast dispatch for per-identifier hook calls (no rest array
  + spread per identifier)
- closure-free scope entry/exit for the internal block/function scope walks
- guard-branch closures only allocated when a guard frame exists
- inline the Identifier left side of assignments past enterPattern
- pin StackedMap stale-view semantics with unit tests

* chore(changeset): split the lazy-path and walker entry from the parser exactness one

* test(js-parser): cover the public inBlockScope delegate

The walkers now enter and leave block scopes through the closure-free cores, so nothing in the repository executed the plugin-facing inBlockScope any more. Assert its contract: a child definitions scope, reset shorthand state, and termination propagating outward only on an executed path.

* style(js-parser): keep plain comments within two lines

Condense the fourteen comments the diff grows past the two-line limit, keeping the invariant each one records.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant