Skip to content

Commit 5321871

Browse files
perf(javascript): minify with webpack's own parser, not terser's
The printer's tree is built by webpack's parser as it finishes each statement, with that parser's tokens and comments, so an asset is read by one parser rather than two. terser's parser stays behind it for what it reads its own way: an expression, `strict`, TypeScript, a line opening an HTML comment, and a source webpack's parser refuses. A token is built only when a node is first given one. The parser reports every token at its deepest, where frames are what it has least of, so nothing is built there: the offsets, kinds and line breaks go into arrays, and the comments of a gap into the list the tokens on both sides share, which is one empty list wherever a gap holds none. Output is byte for byte terser's over the 180 corpus cases and the 288 printer tests. Peak on a real bundle, minified with compress and mangle: 1121 -> 1048 MiB for 8.8 MiB of input, 1591 -> 1529 MiB for 17.3 MiB, with the time unchanged either way.
1 parent 9024861 commit 5321871

4 files changed

Lines changed: 791 additions & 45 deletions

File tree

‎.changeset/097-printer-drop-estree-pre-parse.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": patch
33
---
44

5-
Minify from the printer's own parser, not a tree converted from webpack's.
5+
Minify by parsing with webpack's own parser rather than terser's.

0 commit comments

Comments
 (0)