mirror of
https://github.com/stablyai/orca.git
synced 2026-09-30 08:03:12 +00:00
`worktreeUsesRemoteConnection`, `getRemoteConnectionIdForWorktree`, `worktreeUsesWslPath` and `rightSidebarShowsPullRequestData` each did `Object.values(state.worktreesByRepo).flat().find(...)` plus a linear `repos.find(...)`. They are called from unmemoized Zustand selectors (`use-tab-agent.ts:263`, `use-visible-review-refresh.ts:45`), so every store write re-ran the whole scan once per open tab. Measured on a real instance (10 repos / 423 worktrees / 382 tabs): the `.find()` predicate alone ran 1,320,424 times in 30s — 44,000 worktree visits/sec — while the app was idle. Switched to the existing WeakMap-cached `getIndexedWorktreeMap` / `getIndexedRepoMap` from `store/worktree-repo-index.ts`, matching what `connection-owner-resolution.ts` already does. Same duplicate-id and host-collision semantics; no behavior change. Benchmark at that scale, 200 store writes x 382 tabs x 3 lookups: before 2.762ms per store write after 0.167ms per store write (16.6x) At ~20 store writes/sec that is 55.2ms/sec of renderer CPU down to 3.3ms/sec. The new scale test counts worktree `id` reads: 160,000 before, 800 after.