Repository navigation
perf(renderer): drop redundant worktree card cache-TTL subscription - #13903
Merged
Merged
Conversation
promptCacheTtlMs was a third store subscription for a field the card already reads via foundation.settings; derive it instead. Does NOT bundle the 26 foundation selectors as originally planned. Measured on this store with React (150 cards, 400 unrelated writes, 26 keys): 26 separate useAppStore hooks 100.7ms; one useShallow bundle 402.5ms (4.0x worse); one bundle with a non-allocating keyed compare 141.5ms (1.4x worse). zustand v5 shallow() rebuilds two Maps from Object.entries per compare, and a bundle must still build the whole projection every notification, so collapsing cheap selectors only trades away useSyncExternalStore dispatches that are cheaper than the object it allocates. Listener count would have improved 26 -> 1 while the hot path got slower.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe secondary-details hook now receives 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…tablyai#13903) promptCacheTtlMs was a third store subscription for a field the card already reads via foundation.settings; derive it instead. Does NOT bundle the 26 foundation selectors as originally planned. Measured on this store with React (150 cards, 400 unrelated writes, 26 keys): 26 separate useAppStore hooks 100.7ms; one useShallow bundle 402.5ms (4.0x worse); one bundle with a non-allocating keyed compare 141.5ms (1.4x worse). zustand v5 shallow() rebuilds two Maps from Object.entries per compare, and a bundle must still build the whole projection every notification, so collapsing cheap selectors only trades away useSyncExternalStore dispatches that are cheaper than the object it allocates. Listener count would have improved 26 -> 1 while the hot path got slower.
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.
The finding matters more than the code
This PR was originally scoped to bundle
use-worktree-card-foundation.ts's 26 store subscriptions into oneuseShallowprojection — 26 listeners per card down to 1, across ~100 mounted cards.I measured it before writing it. It is a 4× pessimization. So this PR does not do it.
150 cards x 400 unrelated store writes, median of 5 runs, real store + React:
useAppStorehooks (today)useShallowbundleA vanilla-zustand sweep at 2/5/8/12/20/26 keys showed
useShallowlosing at every key count. There is no crossover to aim for.Mechanism — zustand v5's
shallow()on plain objects falls through tocompareEntries, which allocates twoObject.entries()arrays and twoMaps per comparison, per subscriber, per store write:Measured in isolation against zustand 5.0.14: 721 ns for a 2-key bundle, 2,152 ns for 9-key — versus ~1-5 ns for the equivalent
Object.issweep. Even a perfect zero-allocation compare still loses, because the bundle must rebuild the whole projection on every notification while separate selectors short-circuit on the firstObject.ishit.Listener count is the wrong metric. It would have improved 26 -> 1 here while the hot path got 4x slower. Two sibling branches that did land this transform measured 1.3-1.4x regressions on their own target metric; both are being dropped on the strength of this result.
What actually ships
use-worktree-card-secondary-details.tsno longer opens its own subscription forpromptCacheTtlMs— it derives it fromfoundation.settings, which the same component already subscribes to. 11 -> 10 listeners per card.Staleness is impossible via two independent paths:
use-worktree-card-foundation.ts:36subscribess.settingsunconditionally, andusePromptCacheCountdownStartedAt'suseShallowtuple already includesttlMs.settingsidentity always changes on write — no in-place mutation atsettings.ts:133/160orui.ts:2155.Honestly: this is ~1 listener out of ~30 per card, well under 1% of sidebar notification cost. The measurement is the deliverable.
Validation
typecheck:tsc:webexit 0 (confirmed via--listFilesOnlythat the new test is inside the web tsconfig program, so its casts are genuinely typechecked). Sidebar suite: 225 files / 2,049 tests pass.check:code-quality:changed0 new findings.check:zustand-selector-fanout: 0.0146 ms/write, 0 render invalidations.Guard proven to bite by double revert: reverting the change fails 1 test in hybrid form and 2 of 3 in pure form.
One caveat: the third test ("reports no TTL while suppressed") passes identically on
main— it's a harmless behavior lock, not a regression guard.Caveat on the numbers
Taken on macOS at load average ~24. Ratios and the deterministic sweep survive that; absolute milliseconds are inflated and shouldn't be quoted as app-level figures.
Made with Orca 🐋