GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(javascript): read tree columns directly in the printer's walks by alexander-akait · Pull Request #23403 · webpack/webpack

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Nov 17, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

Cut the minifier's CPU cost on its hottest tree walks, with output unchanged.

  • findNode, the printer's generic walk, goes through a new SyntaxTree#findNode that reads the columns, instead of three accessor calls per child.
  • A.field, A.fieldCount and A.name read the columns themselves instead of calling the tree's accessor.
  • holdsComments binary-searches the few tokens with comments instead of checking every token of the node.

One minify pass (compress, mangle) over 16 unminified production chunks (1.2 MB), cachegrind instruction counts:

Run main This PR Change
--no-opt (what CodSpeed simulates; cold start) 24.49G 21.49G −12.2%
JIT 6.93G 6.70G −3.2%

Wall time per warm pass (~400 ms) is within this container's noise. Output is byte-identical on the 16 chunks and over 107,588 test262 minify runs.

What kind of change does this PR introduce?

perf

Did you add tests for your changes?

No new tests: behavior is unchanged, and the existing JavaScript unit cases (25,132, including the invariants and minify snapshots) cover these paths.

Does this PR introduce a breaking change?

No. findNode is added to the experimental tree and path APIs in types.d.ts.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a. The pending .changeset/085-faster-syntax-parsers.md already covers faster JavaScript minifying.

Use of AI

Claude Code profiled the minifier, wrote the changes, measured instruction counts and compared output over test262 and the production chunks. The author reviewed the results.


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • Added syntax tree node lookup that checks nodes and their children in field order, with support for stopping or continuing traversal based on the test result.
  • Improvements
    • Improved comment-aware printing performance for syntax trees with many tokens.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alexander-akait
perf(javascript): read tree columns directly in the printer's walks
3f9e896
- `findNode` walks the tree's columns through a new `SyntaxTree#findNode`,
  instead of three accessor calls per child.
- `A.field`, `A.fieldCount` and `A.name` read the columns themselves
  instead of calling the tree's accessor.
- `holdsComments` binary-searches the few tokens with comments instead of
  checking every token of the node.

One minify pass over 16 production chunks: 24.23G -> 21.35G instructions
under `--no-opt` (-11.9%), 6.68G -> 6.47G with the JIT (-3.0%). Output is
byte-identical over test262.
@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3f9e896

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 no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added area: parser JavaScript parsing and dependency analysis (lib/javascript, lib/dependencies) area: types types.d.ts, JSDoc annotations, hand-maintained declarations labels Nov 17, 2026
@coderabbitai coderabbitai Bot added the area: build-perf Build time and memory of webpack itself label Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The JavaScript syntax tree adds node traversal, and path accessors read tree storage directly. The syntax printer uses tree traversal and indexes tokens with comment flags to check whether a node range contains comments.

Changes: JavaScript syntax traversal and printing

Layer / File(s) Summary
Tree traversal and path access
lib/javascript/syntax-parser.js
ColumnarSyntaxTree.findNode tests nodes in field order and returns a defined test result or reports whether a descendant matched. JavascriptSyntaxPath exposes this traversal. Its name, fieldCount, and field methods read tree storage directly while preserving their return behavior.
Printer traversal and comment-token lookup
lib/javascript/syntax-printer.js
The printer delegates findNode to A.findNode. It records token indexes with nonzero comment flags and uses binary search in holdsComments to check a node’s inclusive token range. The index is cleared when printing ends.

Possibly related PRs

  • webpack/webpack#22892: Its comment-claiming path uses holdsComments, which this PR changes.
  • webpack/webpack#22815: It introduces the columnar syntax tree layout and accessor contract used by this PR.

Suggested labels: area: parser, area: types, area: build-perf

Suggested reviewers: bjohansebas

Change: Refactor

Merge Risk: Minimal · up to 3f9e8

This change speeds up JavaScript minification by reading syntax-tree storage directly and binary-searching comment tokens, with no intended output change. No concrete regression was found in review, and the author reports identical output on the production chunks and test262 runs. Merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title uses the conventional-commit form perf(javascript): with a valid type (perf) and scope. It states the main change: the printer's tree walks read tree columns directly. The title is specific …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title uses the conventional-commit form perf(javascript): with a valid type (perf) and scope. It states the main change: the printer's tree walks read tree columns directly. The title is specific to the changeset. The branch prefix was not provided, so the check that the type matches the branch prefix cannot be confirmed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

lib/javascript/syntax-printer.js

ast-grep timed out on this file

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

  • X
  • Mastodon
  • Reddit
  • LinkedIn
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: webpack/webpack
  • Branch: perf/javascript-minify-printer
  • File: .coderabbit.yaml
  • Commit: 3f9e896
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8e244c47-c507-46a3-9e3a-bef8ca1c6021
Commits

Reviewing files that changed from the base of the PR and between bfecf32 and 3f9e896.

Files ignored due to path filters: 1

  • types.d.ts is excluded by !types.d.ts
Files selected for processing: 2

  • lib/javascript/syntax-parser.js
  • lib/javascript/syntax-printer.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Reports for 3f9e896, 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
npm i -D webpack@https://pkg.pr.new/webpack@23403
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@23403
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@23403

From Preview package run #13330.


Generated code size

Comparing base (bfecf32) to head (3f9e896). 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 — 10721 — — —

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/): 2477 test(s), 10721 asset(s), 110 emitted nothing.

From Generated code size run #7965.


Types Coverage

Typed lines: 99.64% (194341 of 195034)

Kind Base Head Change
any 45 45 —
unknown 22 22 —
object 18 18 —
Function 1 1 —
untyped 30 30 —

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.

41 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
declarations/WebpackOptions.ts 100.00% 11 2
lib/Compilation.js 99.97% 5 2 3
lib/Compiler.js 100.00% 2 4
lib/loaders/LoaderPlugin.js 99.42% 6
lib/module/NormalModule.js 100.00% 4 1 1
lib/module/NormalModuleFactory.js 100.00% 3 3
lib/javascript/syntax-printer.js 100.00% 5
lib/javascript/JavascriptModulesPlugin.js 100.00% 4
lib/loaders/LoaderOptionsPlugin.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/hmr/HotModuleReplacement.runtime.js 100.00% 2 1
lib/stats/StatsFactory.js 100.00% 2 1
lib/asset/AssetModulesPlugin.js 100.00% 2
lib/config/defineConfig.js 100.00% 2
lib/hmr/JavascriptHotModuleReplacement.runtime.js 100.00% 2
lib/index.js 100.00% 2
lib/loaders/LoaderRunner.js 100.00% 2
lib/module/Module.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/cli.js 100.00% 1
lib/define/DefinePlugin.js 100.00% 1
lib/dll/DllReferencePlugin.js 100.00% 1
lib/graph/ModuleGraph.js 100.00% 1
lib/hmr/HotModuleReplacementPlugin.js 100.00% 1
lib/javascript/JavascriptParser.js 100.00% 1
lib/javascript/syntax-parser.js 100.00% 1
lib/logging/Logger.js 100.00% 1
lib/logging/createConsoleLogger.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/util/makeSerializable.js 100.00% 1
lib/util/terminalColors.js 100.00% 1

From Types Coverage run #4100.


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 12 0
CSS syntax 12 0
HTML syntax 11 0
XML syntax 11 0
JavaScript minifier 13 0
CSS minifier 14 0
HTML minifier 19 0
XML minifier 14 0
JSON minifier 1 0
development build 431 103
production build 439 133
watch with HMR, one rebuild 453 110

From Module loading run #1344.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait merged commit 6151129 into main Nov 17, 2026
54 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait
alexander-akait deleted the perf/javascript-minify-printer branch November 17, 2026 11:08
@codspeed

codspeed Bot commented Nov 17, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 92.93%

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

ℹ️ 38 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

❌ 1 regressed benchmark
✅ 350 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory benchmark "context-esm", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 204.3 KB 2,887.4 KB -92.93%

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-minify-printer (3f9e896) with main (bfecf32)

Open in CodSpeed
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai coderabbitai Bot mentioned this pull request Nov 17, 2026
perf(javascript): walk findNode from a shared stack and read printer lookups in place #23427
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

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

Projects

None yet

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.

1 participant

@alexander-akait
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.