Repository navigation
Commit 4015bbd
authored
perf(css): write selectors, An+B and more values in their shortest spelling (#21664)
* perf(css): reduce more transforms and name the full keyframe `to`
`scale()` with a factor of 1 on one axis is that axis's own function, and a
translation's zero component is zero in either length or percentage. A keyframe
selector of 100% is the `to` CSS Animations 1 §4 names it.
* perf(css): write a selector list in one order, without repeats
A selector list is a set: the same selectors in any order match the same
elements at the same specificity. Writing one canonical order lets equal lists
compress alike and lets two rules naming one set join, and a repeat in it
matches nothing the first already did.
The equivalence harness compares a run of selectors reaching the same block
under the same conditions as the set it is, which is the invariant joining
them into one list already rests on.
* fix(css): part a sibling combinator from a class without a comment
CSS Syntax 3 §4.3.10 starts a number at `+` only before a digit, or before a
`.` that itself has one. Treating every `+.` as a number made `.a+.m` print as
`.a+/**/.m`, longer than the input it came from and different again on a second
pass. A join also drops a selector the other side already names.
* perf(css): write An+B, a 3D matrix and a zero time in their shortest spelling
`An+B` carries its own whitespace, signs and case, an index under 1 matches
nothing so a forward step starts where it does, and a step selecting exactly one
child is the child Selectors 4 §14 names. A 3D matrix whose third row and column
are the identity's is the 2D matrix of the six values it leaves, and a 2D pair of
1 leaves the z scale. A zero time keeps a unit where a zero length drops one, so
it takes the shorter of the two it can carry.
The equivalence harness reads each An+B as the sequence it selects: the engine
folds `even` / `odd` itself but hands `0n+3` back as written.
* perf(css): drop the implied universal inside a selector function
A selector function's argument is a selector like the prelude's, so the
universal a compound implies says nothing there either — `:not(*.g)` is
`:not(.g)`. A lone universal is the selector, a parted one is a combinator
away, and a namespaced one is not implied.
* refactor(css): derive the An+B named equivalents, and split a list only when it is one
The first/last counterpart of each An+B pseudo-class was a table typed into the
printer; it is now read out of the selector table in the generator — the An+B
half by its grammar, the counterpart by the name the pair builds, kept only
where the table has it as a selector too.
The two selector-list helpers were one function apart, and both split every
prelude to find out there was nothing to do: 50,434 of the corpus's 55,055 hold
no comma at all, so a list is only built where one can exist. `scale` and
`rotate3d` asked whether a component was one in two different spellings; both
now use the same test, which also reads `1.0`.
* perf(css): index a rule's declarations once for all three merge tables
Every rule with two declarations was offered to three shorthand tables, and each
built the same property index again: 48,204 Map and Set allocations across the
corpus where one reused pair does. The table scan asked for its longhands
through a closure per entry — 401,700 of them — which is now a loop. And
`_isJoinablePrelude` split every prelude into a list to walk it, where 50,434 of
the corpus's 55,055 hold one selector and need no list at all.
Counted, not timed: the output is byte-identical on all 18 fixtures, and the
wall-clock difference on this machine is inside its own run-to-run spread.
* perf(css): drop a component that spells the property's own initial
`grid-auto-flow:row dense` is the `dense` omitting its group already means. The
keyword is read out of the property table and kept only where it really is the
initial and really is one alternative of a top-level `||` group; which of those
groups falls back to it is the judgement stated in the generator, since
`aspect-ratio:auto 3/2` is a ratio with a fallback rather than the ratio alone.
A rule is also offered to the three merge tables only when two of its properties
are longhands one of them names — 6,238 of the corpus's 8,034 candidate rules
are not, which is 311,900 table-entry checks that no longer run. The union is
built in the generator out of the very arrays it emits, so it cannot drift.
* chore: fold the branch's changeset into one entry
* fix(css): leave an An+B past the safe integer range as written
`_minifyNth` read an unbounded digit run, so a `B` above
`Number.MAX_SAFE_INTEGER` made `b += a` a fixed point and the
normalization loop never exited. Guard both terms and normalize by
modulo instead of by stepping.
Also spell the two new words for cspell, keep the `PAIR_LONGHANDS`
comment with its table, assert the omittable initial keyword is still
one mdn-data states, and canonicalize a nested rule's selector list in
the equivalence harness without rewriting text inside an attribute.
* perf(css): concatenate a join seam instead of canonicalizing it
Deduplicating across the seam re-read the whole accumulated selector list
once per rule joined, so a run of adjacent rules printing the same block
was quadratic: 6000 of them took 2.8s where the base took 0.10s. It
bought nothing measurable — no configCases stylesheet loses a byte
without it — so the seam concatenates and the canonical form stays where
the list is the author's own.
* docs(css): trim two generator comments to the guide's length
* perf(css): read a value's children where they lie rather than listing them
A declaration's value is one component 92 times in 100 (38151 of 41387 on
the Tailwind fixture), and the printer materialized the whole child list
to read its length and first entry. `_valueComponents` and the four
shorthand collapses now walk the child span off the node, so the list is
built only where one is really needed — a custom property's text, a
`unicode-range`, an attribute selector. Young-generation collections for
one Tailwind minify drop from 173 to 165 under a fixed semi-space, and
the emitted bytes are unchanged.
* chore(css): undo an unrelated reformat and cover the omittable-keyword guard
A stale Prettier reformatted eighteen template interpolations the branch
never touched; Prettier 3 leaves interpolations alone, so `fmt:check`
passed either way and the churn stayed in the diff.
The guard that makes a spec change fail generation now takes its tables
the way the other collectors do, so a test can drive it.1 parent bc65f6b commit 4015bbd
16 files changed
Lines changed: 872 additions & 152 deletions
File tree
- .changeset
- lib/css
- test
- configCases/css
- minimize-lightningcss-selectors/__snapshots__
- minimize-selectors
- __snapshots__
- minimize-values
- __snapshots__
- tooling
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| 247 | + | |
247 | 248 | | |
248 | 249 | | |
249 | 250 | | |
| |||
284 | 285 | | |
285 | 286 | | |
286 | 287 | | |
| 288 | + | |
287 | 289 | | |
288 | 290 | | |
289 | 291 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
611 | 611 | | |
612 | 612 | | |
613 | 613 | | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
614 | 618 | | |
615 | 619 | | |
616 | 620 | | |
| |||
879 | 883 | | |
880 | 884 | | |
881 | 885 | | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
882 | 895 | | |
883 | 896 | | |
884 | 897 | | |
| |||
3195 | 3208 | | |
3196 | 3209 | | |
3197 | 3210 | | |
| 3211 | + | |
3198 | 3212 | | |
| 3213 | + | |
3199 | 3214 | | |
3200 | 3215 | | |
3201 | 3216 | | |
| |||
0 commit comments