Repository navigation
Commit 6cccc2d
authored
feat(minify): close size gaps with oxc (#22829)
* feat(minify): close size gaps with oxc
Measured spellings: plain strings as templates, and for outputs up to
1 KB terser's sequences, join_vars, evaluate, conditionals,
collapse_vars and arrows tried off. Folds: a `null` and `undefined`
test of a value read back, `!(a == b || c == d)`, a constant array
iterated by a `for…of` declaring its own name, the truth of a string
longer than its name, unread `Set`s and `Map`s of array literals,
names `void` wrote, literals of different types compared strictly,
writes to a block's unread `let`, a `null` test before an optional
chain, and imports only exported as `export … from`.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minify): move writes into `for…of` heads declaring their own names
An expression statement moves into a `for…in` or `for…of` head declaring
its own names when it reads none of them; a write to a block's `let`
nothing reads drops at the top level too. `reduce_vars`, `unused` and
`side_effects` join the transforms a tiny program is tried without.
oxc's wrong outputs and the getter and conversion-order differences get
reasons of their own.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minify): fold array literal reads, concat chains and pattern keys
`[a].concat([b], 1).concat(x)` as `[a, b, 1].concat(x)`, `[o][0].p` as
`o.p`, `var a; for (a in b)` as `for (var a in b)`, `if (a) break` in a
`do … while (0)` as a guard on what follows, and a pattern's computed
keys read as reads, so a constant key folds. oxc dropping a write in a
`with` body and its direct `eval` get reasons of their own.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minify): fold array literals in templates and a regular expression's source
`${[1, 1]}` as `1,1`, and `/a\/b/.source` as the string the engine
gives back.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minify): keep reads, quotes, targets and dead zones the new folds missed
- count reads in `export default` and exported declarations before moving
an import to `export … from`
- keep a quoted imported name quoted in the re-export
- write `export * as` only where `ecma` is 2020 or later
- keep `[a][0]` as a property target of a destructuring assignment
- keep a direct `eval` out of a `for…in`/`for…of` head declaring `let`s
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minify): keep a `new Set` or `new Map` a `with` or `eval` may rebind
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minify): keep a `concat`, `Set` or `Map` of an array literal with a hole
A hole reads its index through `Array.prototype`.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minify): keep a `Map` whose entry lacks its key or value
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minify): never write a bigint's digits as a template
A bigint literal holds its digits as a string, which the measured template
spelling printed as one: `-1n + ""` became a string negated to a number.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minify): keep the measured trials from changing or breaking the program
- a trial that throws loses: `unsafe` without `evaluate` leaves
`[,].join()` an operand short, as in terser
- a program with a private name is minified again for a names trial, not
printed from its tree, whose renamed private names were named apart
- spellings tried off together and kept on stay on for the option trials
- no template after `await` or `yield`, nor in a member expression,
where one printer wrote it and another did not
- an import moves to `export … from` only whole, as one statement
- a sequence goes into a `for…of` head declaring a `let` only where it
joins as the value, as it needs parens there
Regenerate the schema validators, 35 B smaller gzipped.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* test(minify): assert what the measured trials keep, not which spelling gzip picks
Bun's and Deno's zlib size a program apart from Node's, so the spelling
a measured run keeps differs by runtime.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minify): run a built-in only where the program leaves it, and measure with a smaller window
A call of a global's built-in folds only where `reduce_vars` counts no write
to the global, and no argument holds a hole or a short `Map` entry, which
reads through a prototype. The measured trials gzip with a 16 KiB window,
which finds the same matches in the programs they measure from 192 KiB of
deflate state instead of 256 KiB.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* test(minify): retire the corpus entries the minifier no longer needs
Drop the 174 IMPROVED_YET_BIGGER and 15 OXC_SMALLER entries the corpus
run reports as no longer bigger, and list again the three sources still
1 byte bigger gzipped than oxc's, as on main.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD1 parent e7441b2 commit 6cccc2d
28 files changed
Lines changed: 1433 additions & 758 deletions
File tree
- .changeset
- lib/javascript
- schemas
- plugins
- asset
- container
- css
- debug
- ids
- json
- optimize
- output
- schemes
- sharing
- test
- helpers
- specCases
- unitCases/javascript
- __snapshots__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments