Repository navigation
Commit 358df69
authored
refactor(javascript): minify through webpack's own entry point (#22217)
* refactor(javascript): minify through webpack's own terser entry point
Adds lib/javascript/jsMinify.js beside cssMinify and htmlMinify, so the
default minimizer dispatches JavaScript to a minify function webpack owns
rather than to the one minimizer-webpack-plugin ships, and promotes terser
to a direct dependency. Output is unchanged: a unit test holds jsMinify to
the plugin's terserMinify over every comment-selection, production and
source-map shape.
* perf(javascript): skip the comment callback where nothing is kept or extracted
Adds webpack rows to the printing tables of `compare-js-tools`, measuring
`jsMinify` itself, so a phase webpack takes over is read against what it
replaced. The first thing they showed was our own overhead: handing terser
a comments callback when the answer is "keep none" cost ~20% of the print.
Output is unchanged.
* perf(javascript): mangle names in webpack rather than in terser
Adds a phase skeleton: lib/javascript/terser.js loads terser's own sources
— its published entry point exposes only `minify`, while a phase needs the
classes behind it — and installs the phases webpack implements, each one
declaring through `supports` what it reads. A terser that moved any of it,
or a runtime without dynamic import, keeps terser's own.
The first phase is name mangling. terser rereads a scope's enclosed
definitions for every candidate name, which is quadratic in the one big
scope a bundle has; asking a set built once is not. Mangling drops 29-47%
on large bundles (2958ms to 1572ms on typescript.js), 3.7-4.8% off a whole
minify run, with byte-identical output.
* refactor(javascript): name the minifier seam after what it becomes
`terser.js` and `terserMangle.js` are now `syntax-printer.js` and
`syntax-mangle.js`, and the public entry is `webpack.javascript.printer`.
terser is what stands behind the seam today, not what the seam is.
* refactor(javascript): give JavaScript the syntax pair css and html have
`syntax.js` is now the barrel naming both halves — `parser` and `printer` —
reached through getters, so parsing never loads the printer and printing
never loads the parser. What was `syntax.js` is `syntax-parser.js`, and
`webpack.javascript.syntax` is the public face, as for css and html.
Two merges while the names moved: the mangle phase into the printer it is
installed by, and `ChunkFormatHelpers` into `ChunkHelpers` — the latter
reads `StartupHelpers` inside the hash handler, since those two would
otherwise wait on each other at load time.
* refactor(javascript): keep the parser's Unicode tables in one module
`regexpData.js` folded into `data.js`, and the generator emits one file
rather than two. It costs every build the 21KB of property tables a
rejected pattern used to pay for on its own: measured at 1.18ms and 128KB
of heap for the module, against 1.17ms and 81KB before.
* refactor(javascript): one parser file instead of two
`parser.js` folded into `syntax-parser.js`, which had grown its own copies of
23 of its definitions — the scope and binding constants, `nextLineBreak`,
`stringToNumber`, `getLineInfo` and the rest. Two names could not survive
the union: the class `Node` collided with the `NodeLike` alias the layer
above reads under that name, and `SourceLocation` with estree's, so both
classes now say `Parser` in their names.
* refactor(javascript): fold the grammar into the parser
The grammar lived in its own file and was copied onto `Parser.prototype`
on the first parse. A build that parses at all pays that install, so the
laziness bought nothing, and patching the prototype after the class exists
costs what it saves: parsing typescript.js runs ~15% faster with the
productions declared in the class body (warm median 915ms vs 1084ms over
7 interleaved processes per arm; terser's bundle ~8% faster).
`regexp.js` stays lazy — only a pattern the host engine itself rejected
reaches it.
* chore: fold the grammar merge into the parsing changeset
* fix(test): point the parser benchmark at syntax-parser
`lib/javascript/syntax.js` is the parser/printer barrel now, so the
`js-parser-unit` benchmark read `WebpackParser` as undefined and the
benchmark-memory job died on it. Also updates the prose still naming the
old path.
* fix(test): keep jsMinify out of coverage instrumentation
`minimizer-webpack-plugin` ships a minify function to its workers as
source, so the counters istanbul injects resolve to nothing there and
every production build under coverage failed with `cov_… is not
defined`. cssMinify and htmlMinify are excluded for that reason already.
* chore: keep the changeset sentence within 80 characters
* fix(test): state the printer's fallback where terser's sources cannot load
Deno cannot import terser's own sources through `load`, so it hands back
terser's published entry point with no phase installed — which the test
asserted could never happen. It now states both halves of that contract.1 parent 6b15260 commit 358df69
41 files changed
Lines changed: 20095 additions & 18653 deletions
File tree
- .changeset
- lib
- asset
- config
- esm
- javascript
- util
- test
- benchmarkCases/js-parser-unit
- unitCases
- __snapshots__
- tooling
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
603 | 603 | | |
604 | 604 | | |
605 | 605 | | |
606 | | - | |
| 606 | + | |
607 | 607 | | |
608 | 608 | | |
609 | 609 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
392 | 388 | | |
393 | 389 | | |
394 | 390 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2524 | 2524 | | |
2525 | 2525 | | |
2526 | 2526 | | |
2527 | | - | |
2528 | | - | |
2529 | | - | |
2530 | | - | |
2531 | | - | |
| 2527 | + | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
2532 | 2532 | | |
2533 | 2533 | | |
2534 | 2534 | | |
| |||
2557 | 2557 | | |
2558 | 2558 | | |
2559 | 2559 | | |
2560 | | - | |
2561 | | - | |
2562 | | - | |
| 2560 | + | |
| 2561 | + | |
| 2562 | + | |
| 2563 | + | |
2563 | 2564 | | |
2564 | 2565 | | |
2565 | | - | |
| 2566 | + | |
2566 | 2567 | | |
2567 | 2568 | | |
2568 | 2569 | | |
| |||
2594 | 2595 | | |
2595 | 2596 | | |
2596 | 2597 | | |
2597 | | - | |
| 2598 | + | |
2598 | 2599 | | |
2599 | 2600 | | |
2600 | 2601 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
0 commit comments