Repository navigation
perf(cache): use a Set for the props-cache variant key lookup - #327
Merged
Merged
Conversation
tianenpang
added a commit
that referenced
this pull request
Nov 26, 2026
* perf(cache): use a Set for the props-cache variant key lookup (#327) * chore: bump dependencies to latest * fix: make cold and cached calls agree on compound and prototype-named variants * chore: bump node version * feat(types): add defineVariants and let VariantProps read it (#326) * feat(types): add defineVariants and let VariantProps read it A tv() config kept in its own variable stops compiling once it has compoundVariants: their values are inferred as string, which tv() rejects. defineVariants is an identity helper with tv()'s generics that keeps the literals, so the config is checked where it is written and passes back into tv() unchanged. - export TVOptions, the options type tv() and the lite tv() shared inline - export defineVariants from the default, lite and config entries - VariantProps accepts a defineVariants result, identical to its recipe's * feat(types): keep written fields required on defineVariants options The options defineVariants returns now carry only the fields that were written, as required keys, and type each default as any value its variant accepts, so app code can read one back: const size: 'sm' | 'lg' = buttonVariants.defaultVariants.size; VariantProps reads the fields directly instead of matching the old shape. * docs(types): call the defineVariants example config buttonTheme HeroUI names its tv() recipes buttonVariants, so the same name on a config read the wrong way round. * fix(types): tighten defineVariants and VariantProps types * chore(biome): update schema version to 2.6.8 * perf(cache): key the props cache on variant and compound keys only --------- Co-authored-by: Gal Be <galevgi@gmail.com> Co-authored-by: Mathieu Laurent <mathieu.laurent@monizze.be>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
createPropsCachenow keeps the variant keys in aSet.collectExtraKeyschecks them for each prop on every cached call, andSet.hasis faster than the object lookup. The output does not change.Built
dist, µs per loop, 20 rounds, Mann-Whitney test (Node 24, Apple M2 Max):extendchain callstwMerge: falseWhat is the purpose of this pull request?
Performance impact
pnpm benchmarksuite and reviewed the current TV versus released TV results.Full
pnpm benchmark, 2 rounds: TV rows median +1.0%,extend-multi+10.8%.utilities/mergewas −6.2%, but it does not use this code, and the released-package control moved +7.3% on the same row.vitest,tsc,biomeand the build pass. Outputs matched on 1M random configs.Before submitting the PR, please make sure you do the following
fixes #123).