Repository navigation
Commit 70f8a56
authored
feat(css): minify custom-property whitespace, merge longhands past a nested rule (#21773)
* feat(css): minify the whitespace between a custom property's tokens
A custom property's tokens are the value the CSSOM hands back, so none of
them is rewritten — but the whitespace between two of them only says they
are two. A run of it is now the one space they need, and nothing at all
where a comma or a block edge already parts them.
Also folds the two spaces a dropped comment used to leave into one, and
teaches the equivalence oracle that whitespace beside `[]` / `{}` is as
insignificant as beside `()`, which it already normalized.
* feat(css): merge a longhand family in a block that holds a nested rule
The merge was skipped for the whole block as soon as it held one child
rule, because a rule between two longhands would be stepped over and the
adjacency scan reads declarations only. Count the child rules standing
before each declaration instead, so only a rule *inside* a family's span
blocks that family — a nested `@supports` re-declaring a longhand still
does, one standing after the four no longer does.
Costs nothing where it cannot pay: the counts are built only once a block
is known to hold two mergeable longhand names.
* fix(css): drop a shadow's trailing zero written with a unit
`_dropShadowZeroLengths` reads the components as authored — the zero-unit
drop prints later — but tested them against the bare string "0", so
`box-shadow:0 0 0 0 red` collapsed and `box-shadow:0px 0px 0px 0px red`
did not. Whether the collapse ran came down to which spelling the author
happened to use.
Test the components with `_isZeroLength`, which is what the rest of the
printer already asks. `0%` stays a percentage, which a shadow's <length>
slots do not take.
* docs(css): record why a string's hex escape is left as written
csso and lightningcss write the character a hex escape names. It is
value-identical, so the reason not to follow them is a measurement:
over 19 framework stylesheets it saves 6420 raw bytes and costs 593 gzip
ones, because an escape is a repetitive ASCII alphabet where the
character is a 3-byte UTF-8 run. The benchmark says the same from the
other side — on Font Awesome lightningcss is 3.8 KB smaller raw and
0.3 KB bigger gzipped.
Written next to `_minifyString`, where the change would be made, and
pinned by two configCases lines.
* docs: state which size column a change is accepted on
The guide already observed that raw and compressed bytes disagree; it
never said which one decides. Make it a rule: gzip decides, raw is the
tiebreak, and the seam they part along is removing information (shrinks
both, always) against re-encoding it (has to show a compressed win).
Both refusals webpack ships on size grounds — convertLengthUnits, and
leaving a string's hex escape as written — sit on the re-encoding side,
so the rule is descriptive of what is already there rather than new
policy.
* build: report the deciding size column in the size tools
All three tools already measured raw/gzip/brotli/zstd; what they led
with was raw, which is the column a change should not be accepted on.
Code Size report: the verdict table gains `Gzip change` and `Gzip
new/gone` beside the raw pair, the per-asset compressed columns carry
bytes as well as a percentage (a real move on a small asset rounds to
0.00%, and percentages do not add up across rows), and the row budget
ranks on whichever of raw and gzip moved further so a re-encoding that
barely moves raw cannot be truncated away.
Both minifier benchmarks: `saved` now reads off gzip and sits beside it;
raw stays first as the tiebreak.
The stored report shape is unchanged — gzip was always in it — so an
existing baseline stays comparable and REPORT_VERSION does not move.
* fix(css): mark a size row by gzip, and close up custom-property blocks
Addresses the review on #21773.
The Code Size row marker read `delta.raw` first, so an asset that lost a
raw byte and gained a gzip one printed 🟢 — which the report on this very
pull request did, for `minimize-lightningcss-values`. It follows gzip
now, with raw the tiebreak.
A custom property kept the whitespace beside a block delimiter although
nothing fuses across one, so `a [b] c` stayed as written where `foo( 1 )`
already closed up. Both sides of `[`, `{`, `)`, `]` and `}` now go; `(`
is the exception, since an identifier in front of it makes a function
token, and `_wouldFuseTokens` still wins wherever it applies.
Also: AGENTS.md no longer claims removing bytes always shrinks gzip — it
does not, and `css/minimize bundle0.css` in this pull request's own size
report is the counterexample (raw -1 B, zstd +1 B); the changeset is back
under 80 characters; and thirteen comments are trimmed to the two lines
the guide asks for.
* docs: reword the block-boundary fixture note and tighten the size rule
Addresses the second review on #21773. The fixture's kept comment read
`bar \`(\`, which an identifier in front of turns into a function token`,
which parses badly; it now says what it means. The removal-vs-re-encoding
bullet is tightened — it grew a clause when the previous round asked for
the "always" to be qualified.1 parent 2502bbd commit 70f8a56
19 files changed
Lines changed: 357 additions & 122 deletions
File tree
- .changeset
- lib/css
- test
- configCases/css
- minimize-esbuild/__snapshots__
- minimize-lightningcss-values/__snapshots__
- minimize-timing-functions
- __snapshots__
- minimize-values
- __snapshots__
- minimize
- helpers
- tooling
| 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 | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
277 | 286 | | |
278 | 287 | | |
279 | 288 | | |
| |||
580 | 589 | | |
581 | 590 | | |
582 | 591 | | |
583 | | - | |
| 592 | + | |
584 | 593 | | |
585 | | - | |
| 594 | + | |
586 | 595 | | |
587 | 596 | | |
588 | 597 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3174 | 3174 | | |
3175 | 3175 | | |
3176 | 3176 | | |
3177 | | - | |
3178 | | - | |
3179 | | - | |
| 3177 | + | |
| 3178 | + | |
3180 | 3179 | | |
3181 | 3180 | | |
3182 | 3181 | | |
| |||
7647 | 7646 | | |
7648 | 7647 | | |
7649 | 7648 | | |
| 7649 | + | |
| 7650 | + | |
7650 | 7651 | | |
7651 | 7652 | | |
7652 | 7653 | | |
| |||
8049 | 8050 | | |
8050 | 8051 | | |
8051 | 8052 | | |
8052 | | - | |
8053 | | - | |
8054 | | - | |
8055 | | - | |
8056 | | - | |
8057 | | - | |
8058 | | - | |
8059 | | - | |
8060 | | - | |
8061 | | - | |
8062 | | - | |
8063 | | - | |
8064 | | - | |
8065 | | - | |
8066 | | - | |
8067 | | - | |
8068 | | - | |
8069 | | - | |
8070 | | - | |
8071 | | - | |
8072 | | - | |
8073 | | - | |
8074 | | - | |
8075 | | - | |
| 8053 | + | |
| 8054 | + | |
| 8055 | + | |
| 8056 | + | |
8076 | 8057 | | |
8077 | 8058 | | |
8078 | 8059 | | |
| |||
8083 | 8064 | | |
8084 | 8065 | | |
8085 | 8066 | | |
| 8067 | + | |
| 8068 | + | |
| 8069 | + | |
| 8070 | + | |
| 8071 | + | |
8086 | 8072 | | |
8087 | | - | |
8088 | 8073 | | |
8089 | 8074 | | |
8090 | | - | |
8091 | | - | |
| 8075 | + | |
| 8076 | + | |
| 8077 | + | |
| 8078 | + | |
| 8079 | + | |
| 8080 | + | |
| 8081 | + | |
| 8082 | + | |
| 8083 | + | |
| 8084 | + | |
| 8085 | + | |
| 8086 | + | |
8092 | 8087 | | |
| 8088 | + | |
| 8089 | + | |
| 8090 | + | |
| 8091 | + | |
| 8092 | + | |
| 8093 | + | |
| 8094 | + | |
| 8095 | + | |
| 8096 | + | |
| 8097 | + | |
| 8098 | + | |
| 8099 | + | |
| 8100 | + | |
| 8101 | + | |
| 8102 | + | |
| 8103 | + | |
| 8104 | + | |
| 8105 | + | |
| 8106 | + | |
| 8107 | + | |
| 8108 | + | |
| 8109 | + | |
| 8110 | + | |
| 8111 | + | |
| 8112 | + | |
| 8113 | + | |
| 8114 | + | |
| 8115 | + | |
| 8116 | + | |
| 8117 | + | |
| 8118 | + | |
| 8119 | + | |
| 8120 | + | |
| 8121 | + | |
| 8122 | + | |
| 8123 | + | |
| 8124 | + | |
8093 | 8125 | | |
8094 | | - | |
8095 | 8126 | | |
8096 | 8127 | | |
8097 | 8128 | | |
| 8129 | + | |
| 8130 | + | |
| 8131 | + | |
| 8132 | + | |
| 8133 | + | |
| 8134 | + | |
| 8135 | + | |
| 8136 | + | |
8098 | 8137 | | |
8099 | 8138 | | |
8100 | | - | |
8101 | | - | |
| 8139 | + | |
| 8140 | + | |
| 8141 | + | |
8102 | 8142 | | |
8103 | 8143 | | |
8104 | 8144 | | |
| |||
8108 | 8148 | | |
8109 | 8149 | | |
8110 | 8150 | | |
8111 | | - | |
8112 | | - | |
| 8151 | + | |
| 8152 | + | |
8113 | 8153 | | |
8114 | 8154 | | |
8115 | 8155 | | |
| |||
8376 | 8416 | | |
8377 | 8417 | | |
8378 | 8418 | | |
8379 | | - | |
| 8419 | + | |
| 8420 | + | |
| 8421 | + | |
8380 | 8422 | | |
8381 | 8423 | | |
8382 | 8424 | | |
| |||
9234 | 9276 | | |
9235 | 9277 | | |
9236 | 9278 | | |
| 9279 | + | |
| 9280 | + | |
9237 | 9281 | | |
9238 | 9282 | | |
9239 | | - | |
| 9283 | + | |
| 9284 | + | |
| 9285 | + | |
| 9286 | + | |
| 9287 | + | |
| 9288 | + | |
| 9289 | + | |
| 9290 | + | |
| 9291 | + | |
| 9292 | + | |
9240 | 9293 | | |
9241 | 9294 | | |
9242 | 9295 | | |
| |||
9259 | 9312 | | |
9260 | 9313 | | |
9261 | 9314 | | |
| 9315 | + | |
| 9316 | + | |
| 9317 | + | |
| 9318 | + | |
| 9319 | + | |
| 9320 | + | |
| 9321 | + | |
9262 | 9322 | | |
9263 | 9323 | | |
9264 | 9324 | | |
| |||
10489 | 10549 | | |
10490 | 10550 | | |
10491 | 10551 | | |
10492 | | - | |
10493 | | - | |
10494 | | - | |
10495 | | - | |
10496 | | - | |
| 10552 | + | |
| 10553 | + | |
10497 | 10554 | | |
10498 | 10555 | | |
10499 | 10556 | | |
| |||
10592 | 10649 | | |
10593 | 10650 | | |
10594 | 10651 | | |
10595 | | - | |
10596 | | - | |
10597 | | - | |
10598 | | - | |
| 10652 | + | |
| 10653 | + | |
| 10654 | + | |
10599 | 10655 | | |
10600 | 10656 | | |
10601 | 10657 | | |
| |||
10616 | 10672 | | |
10617 | 10673 | | |
10618 | 10674 | | |
| 10675 | + | |
| 10676 | + | |
| 10677 | + | |
| 10678 | + | |
| 10679 | + | |
| 10680 | + | |
| 10681 | + | |
| 10682 | + | |
| 10683 | + | |
| 10684 | + | |
| 10685 | + | |
| 10686 | + | |
| 10687 | + | |
| 10688 | + | |
| 10689 | + | |
| 10690 | + | |
10619 | 10691 | | |
10620 | 10692 | | |
10621 | 10693 | | |
| |||
10624 | 10696 | | |
10625 | 10697 | | |
10626 | 10698 | | |
10627 | | - | |
| 10699 | + | |
| 10700 | + | |
10628 | 10701 | | |
10629 | 10702 | | |
10630 | 10703 | | |
| |||
0 commit comments