Skip to content

perf(cache): use a Set for the props-cache variant key lookup - #327

Merged
tianenpang merged 1 commit into
heroui-inc:canaryfrom
g4lb:perf-cache-variant-key-set
Nov 25, 2026
Merged

tianenpang merged 1 commit into
heroui-inc:canaryfrom
g4lb:perf-cache-variant-key-set

Conversation

@g4lb

@g4lb g4lb commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Description

createPropsCache now keeps the variant keys in a Set. collectExtraKeys checks them for each prop on every cached call, and Set.has is 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):

Benchmark Before After Change
extend chain calls 23.5 21.6 −8.1%
custom config calls 27.2 25.2 −7.3%
button calls, twMerge: false 68.0 64.9 −4.7%
button calls 68.9 65.8 −4.4%
button, same props 61.2 58.8 −4.0%
mixed page 20.7 19.9 −3.6%

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Performance impact

  • This change is not performance-sensitive.
  • I ran the full pnpm benchmark suite and reviewed the current TV versus released TV results.
  • Any confirmed regression above 5% is documented and intentionally bounded.

Full pnpm benchmark, 2 rounds: TV rows median +1.0%, extend-multi +10.8%. utilities/merge was −6.2%, but it does not use this code, and the released-package control moved +7.3% on the same row.

vitest, tsc, biome and the build pass. Outputs matched on 1M random configs.

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Follow the Style Guide.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Confirm that performance-sensitive changes follow the benchmark requirements.

@tianenpang
tianenpang changed the base branch from main to canary November 25, 2026 13:22
@tianenpang
tianenpang merged commit 4919a82 into heroui-inc:canary Nov 25, 2026
6 of 7 checks passed
@tianenpang tianenpang mentioned this pull request Nov 26, 2026
8 of 12 tasks
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants