Repository navigation
Conversation
A group with one candidate can never collapse, but it still pre-computed all utilities (~750 ms with the default theme) to fill the static index. E.g.: the first `flex hover:underline` took ~760 ms instead of ~6 ms.
Pre-computing all utilities to collapse a group made the first collapse of a class list with only static utilities take ~800 ms with the default theme, e.g. `flex items-center`, which took ~2 ms before. A group of static utilities only needs the static utilities in the index, e.g. `overflow-x-hidden overflow-y-hidden` → `overflow-hidden`. So compute the properties of the 889 static utilities instead, once per design system, which adds them to the index. This takes ~4 ms (~15 ms with a cold JIT). With the default theme, no group of static utilities collapses into a utility with a value. Candidates with a value, like `p-4`, already pre-compute all utilities while they are canonicalized, so groups with them work as before.
Collapsing a group of static utilities first computes the properties of all static utilities, so that the result does not depend on the candidates that were canonicalized before. That costs ~14ms on a fresh design system, but it isn't always needed: - A group with fewer than 2 utilities can't be collapsed, e.g. `group flex`, where `group` isn't a utility. Return early, before computing the static utilities (14ms → 1ms). - When all utilities were pre-computed already (for a candidate with a value like `p-4`), the static utilities are in the index already. With a prefix, we computed all of them a second time under their prefixed name (3-6ms → 0ms). The static pass now also skips the static utilities that the class list skips, like the deprecated `bg-gradient-to-r`. These are not computed when pre-computing all utilities either, so the index is the same in both orders, and a collapse never picks a deprecated name.
|
I pushed three small commits on top of this PR, to bring the cost of the fix down to a few ms:
First call on a fresh design system with the default theme, median of 7 runs:
The output is the same as before my commits. The tests also cover a prefix, the result after a candidate with a value, and that these groups don't read the full class list. Sent by an AI assistant on behalf of @RobinMalfait. |
A prefix like `o` is also the start of `overflow-hidden`, so the check `startsWith(prefix)` skipped adding the prefix. Pre-computing all utilities then indexed `overflow-hidden` instead of `o:overflow-hidden`, and a later `o:overflow-x-hidden o:overflow-y-hidden` didn't collapse.
|
thanks this holds up the variant signature cache had the same prefix check so with |
Summary
part of #20602
collapsing static utilities like
overflow-x-hidden overflow-y-hiddenintooverflow-hiddenonly worked after some earlier candidate built the pre-computed utilities since that is what indexes static utilities by property and valuecollapse now computes the properties of the static utilities first so the result no longer depends on what was canonicalized before
utilities and variants whose name starts with the prefix like
o:outline-[2px]withprefix(o)now canonicalize toothe arbitrary line height cases from the issue comment are left out since they touch the same code as #20603
Test plan
added regression tests that collapse
overflow-x-hidden overflow-y-hiddenandoverflow-x-clip overflow-y-clipandoverscroll-x-none overscroll-y-noneon a new design system which fail on main and pass nowpnpm vitest run src/canonicalize-candidates.test.tsin packages/tailwindcss passes