perf(tv): memoize slot invocations with simple args#6737
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/utils/tv.spec.ts`:
- Around line 162-165: Rename the test case around build to clarify that it
verifies identical output for reordered keys, not memoization cache reuse; leave
the assertion and implementation unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3b50c4c8-f271-457c-b88c-ebc679c4ffdb
📒 Files selected for processing (2)
src/runtime/utils/tv.tstest/utils/tv.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/runtime/utils/tv.ts
🔗 Linked issue
Relates to #6293
❓ Type of change
📚 Description
Every render re-invokes the tv slot functions (
ui.base(),ui.label(),ui.td(), ...), re-running variant resolution and twMerge even when the arguments are identical to the previous call — per table cell, per navigation item, per re-render. tailwind-variants caches nothing across invocations, and CPU profiling showed this as the largest remaining theming cost after the reactivity fixes in #6736.This memoizes slot invocations in the
tvwrapper when the arguments are fully serializable: primitives and arrays of primitives. Anything else, clsx-style object classes and the(defaults) => classesreplacer functions from #6562, bails to the existing uncached path, so those semantics are untouched (covered bytest/utils/tv.spec.ts).JSON.stringifyis used as the cache key, and its dropping ofundefinedvalues matches tv's own treatment of undefined variants. The cache lives on the invocation result, so anapp.config.uichange or a variant-prop recompute starts fresh, and each slot's cache is capped at 500 entries to guard against pathological dynamic inputs.Measured with the benchmarks from #6728/#6736: a 100-cell
ui.td()loop goes from 5,510 to 73,962 ops/s (13.4x), and a Button re-render from 4,103 to 5,235 ops/s on top of #6736 (2x cumulatively vsv4). Output classes are byte-identical: full suite passes with zero snapshot changes.📝 Checklist