orca/src
Neil f48cb78646
perf(store): index worktrees and tabs once per hydration loop (#10891)
* perf(store): index worktrees and tabs once per hydration loop

Four sites in hydrateWorkspaceSession and reconnectPersistedTerminals rebuilt a
flattened array inside a loop and linearly searched it:

  Object.values(worktreesByRepo).flat().find((e) => e.id === worktreeId)

That is O(rows x ids) for O(rows + ids) distinct work. Build one first-wins index
per loop instead. Neither loop sets state or awaits, so a single index over the
store snapshot is valid for every iteration.

54.5x at a real 10-repo / 423-worktree session with 188 pending reconnects;
2.1x on a one-repo session. This runs synchronously on renderer cold start and
gates workspaceSessionReady, which blocks terminal pane mounting.

First-wins matters: Array.prototype.find returns the first match, so an index
that overwrote on collision would resolve a different repo for a duplicated
worktree id. Both the tests and the benchmark fixture carry a deliberate
cross-repo duplicate so that difference is observable.

Co-authored-by: Orca <help@stably.ai>

* test(store): count the generated worktree rows instead of multiplying

Review feedback: the table printed repoCount * worktreesPerRepo, which misses the
duplicate id makeStore injects for multi-repo cases (that duplicate is what makes
first-wins observable). Count the generated map, and say plainly that the fixtures
are synthetic at real-world scale rather than a replay of a real session.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-07-27 17:09:31 -07:00
..
cli fix(runtime): refuse SSH hosts in project setup instead of acting locally (#10799) 2026-07-27 16:21:54 -07:00
main perf(relay): keep the PTY replay window as chunks, not a re-sliced string (#10900) 2026-07-27 16:40:59 -07:00
preload fix(resource-manager): never destroy a session Orca cannot prove is idle (#8459) (#10893) 2026-07-27 11:52:55 -07:00
relay perf(relay): keep the PTY replay window as chunks, not a re-sliced string (#10900) 2026-07-27 16:40:59 -07:00
renderer perf(store): index worktrees and tabs once per hydration loop (#10891) 2026-07-27 17:09:31 -07:00
shared fix(git-history): stop reading the option marker as the resolved ref name (#10906) 2026-07-27 16:40:56 -07:00
types