Repository navigation
perf(remote): read the repo catalog once per publish, not once per worktree - #18410
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughThe remote workspace publish handler now creates one repository execution-host lookup and one memoizing worktree target resolver per publish. Target export functions reuse this resolver across connected targets. The handler skips session and repository reads when no target is connected. Tests verify catalog-read reuse, worktree-resolution reuse, and the idle path. Merge Risk: ⚪ Minimal · up to Remote workspace publishing now reuses repository and worktree resolution within a publish while preserving existing session behavior. The idle-path regression is covered, and no current merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description is detailed and covers the change, rationale, testing, visual proof, review notes, and checklist. However, the required Linked Issue section is marked N/A even though the template requires an issue link.
✨ Finishing Touches 💡 1📝 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 |
There was a problem hiding this comment.
ℹ️ Minor suggestion only — one edge case on the zero-target path.
Reviewed changes
- Hoist the repo catalog read —
createRepoRowExecutionHostLookup(store.getRepos())now runs once per publish rather than once per worktree, threaded throughexportSessionForTarget→targetForWorktree. - Regression guard —
getReposbecomes a trackedvi.fn, and a new test asserts a 12-worktree publish reads the catalog exactly once.
The optimization is sound: exportRemoteWorkspaceSession is synchronous, and every exportSessionForTarget call runs to completion inside the targets.map callback before the first await, so the hydrated rows cannot change between the hoist and the last use. The shared lookup is also target-independent (resolution compares the resolved connection id against targetId), so reusing one snapshot across all targets is correct.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — the memoization is sound; one comment nit inline.
Reviewed changes
- Memoised per-worktree ownership resolution —
createWorktreeTargetResolvercachestargetForWorktreeresults for the life of a single publish, keyed on(worktreeId, executionHostId), so exporting to N targets resolves each worktree once instead of N times. - Added a resolution-count regression guard — a new test wraps
resolveWorktreeExecutionHostwith a call counter and asserts a 6-worktree × 2-target publish resolves ownership exactly 6 times.
The memoization is correct: within one publish targetForWorktree is a pure function of (worktreeId, executionHostId) given a fixed repoLookup, so caching the resolved connection id (or null) across targets is safe. The Map correctly distinguishes a cached null from a missing entry via cached !== undefined, and executionHostId participates in the key, which matters because the lastVisitedAtByWorktreeId loop resolves host-qualified keys with a non-null host id that changes the answer. The NUL separator is collision-free since neither id can contain NUL.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
…rktree `remoteWorkspace:setForConnectedTargets` costs 13 ms of main-thread time per call at 0.48 calls/sec — 0.63% of wall on a real session, the second most expensive IPC handler in the main process. Almost all of it is one line. `exportRemoteWorkspaceSession` asks `isTargetWorktree(worktreeId)` once per worktree in the session, and that callback called `targetForWorktree(store, ...)`, which called `store.getRepos()` — and `getRepos()` maps `hydrateRepo` over every repo row. So publishing to one SSH target re-hydrated the whole repo catalog once per worktree, then threw a fresh `createRepoRowExecutionHostLookup` (which itself `filter`s the catalog per lookup) away each time. The lookup is now built once per handler invocation and shared across targets: the rows cannot change inside one synchronous projection, and they are the same for every target. On the session that surfaced this — 413 worktrees, 13 repos, 1 connected target — that is 413 catalog hydrations (5369 `hydrateRepo` calls) per publish reduced to 1 (13 calls). The repo normaliser reached through `hydrateRepo` was the #2 self-time function in a 30 s main-process CPU profile at 0.25%. No user-facing trade-off: identical ownership resolution, identical exported session, identical stale-revision handling.
Follow-up on the same handler: hoisting `store.getRepos()` removed the repeat hydration, but the ownership resolution itself was still repeated once per connected target. `targetForWorktree` computes a connection id from the repo catalog alone — only the final `=== targetId` differs — so exporting to N targets ran the identical resolution N times over every worktree key, and the projection asks the question once per key of `tabsByWorktree`, `activeTabIdByWorktree`, `lastVisitedAtByWorktreeId` and `defaultTerminalTabsAppliedByWorktreeId`. Resolutions are now memoised for the life of one publish, keyed on `(worktreeId, executionHostId)` because both participate in resolution. Test asserts 6 worktree keys resolve 6 times across 2 targets instead of 12.
… is connected Hoisting the catalog read made a zero-connected-target publish pay for a full repo hydration it never did before. Return early instead.
5dcc791 to
204d54f
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Bot review resolution: pullfrog — zero-target path still hydrates the catalog. Fixed in pullfrog — line 278 comment misstates the memo. Fixed in coderabbit — Description check. Fixed: added the Linked Issue, Visual Proof ( coderabbit — Docstring Coverage 16.67% vs 80% threshold. Declining. coderabbit — inline review. "No actionable comments were generated." Nothing to action. Also rebased onto current |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Since the prior review (memoization at 5dcc791), this delta adds the zero-target early return:
- Early return on the disconnected path —
if (targets.length === 0) return []now runs beforestore.getWorkspaceSession()andstore.getRepos(), so a hydrated-but-disconnected target no longer pays a full repo hydration per publish (a regression the hoisted catalog read introduced, on a handler firing ~0.48/sec). - Regression guard — a new test asserts the zero-connected-target publish returns
[]while reading neither the session nor the repo catalog. - Comment reword — the misleading "one ownership resolution for every target" is now "ownership resolutions shared across targets."
The early return is behavior-preserving: a zero-target publish previously ended in Promise.all([]).filter(...) → [], so returning [] up front skips only the reads. Both prior review threads are addressed cleanly, and the 10 tests in the file pass.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
CI note: Evidence:
Everything else is green, including |
…rktree (stablyai#18410) * perf(remote): read the repo catalog once per publish, not once per worktree `remoteWorkspace:setForConnectedTargets` costs 13 ms of main-thread time per call at 0.48 calls/sec — 0.63% of wall on a real session, the second most expensive IPC handler in the main process. Almost all of it is one line. `exportRemoteWorkspaceSession` asks `isTargetWorktree(worktreeId)` once per worktree in the session, and that callback called `targetForWorktree(store, ...)`, which called `store.getRepos()` — and `getRepos()` maps `hydrateRepo` over every repo row. So publishing to one SSH target re-hydrated the whole repo catalog once per worktree, then threw a fresh `createRepoRowExecutionHostLookup` (which itself `filter`s the catalog per lookup) away each time. The lookup is now built once per handler invocation and shared across targets: the rows cannot change inside one synchronous projection, and they are the same for every target. On the session that surfaced this — 413 worktrees, 13 repos, 1 connected target — that is 413 catalog hydrations (5369 `hydrateRepo` calls) per publish reduced to 1 (13 calls). The repo normaliser reached through `hydrateRepo` was the stablyai#2 self-time function in a 30 s main-process CPU profile at 0.25%. No user-facing trade-off: identical ownership resolution, identical exported session, identical stale-revision handling. * perf(remote): resolve each worktree's owning target once per publish Follow-up on the same handler: hoisting `store.getRepos()` removed the repeat hydration, but the ownership resolution itself was still repeated once per connected target. `targetForWorktree` computes a connection id from the repo catalog alone — only the final `=== targetId` differs — so exporting to N targets ran the identical resolution N times over every worktree key, and the projection asks the question once per key of `tabsByWorktree`, `activeTabIdByWorktree`, `lastVisitedAtByWorktreeId` and `defaultTerminalTabsAppliedByWorktreeId`. Resolutions are now memoised for the life of one publish, keyed on `(worktreeId, executionHostId)` because both participate in resolution. Test asserts 6 worktree keys resolve 6 times across 2 targets instead of 12. * perf(remote): skip the session and repo reads when no hydrated target is connected Hoisting the catalog read made a zero-connected-target publish pay for a full repo hydration it never did before. Return early instead.

ELI5
When Orca publishes your workspace to a connected SSH host, it walks every worktree and asks "does this one belong to that host?"
To answer, it fetched the entire repo catalog and re-built it from scratch — every single time, for every single worktree. 413 worktrees meant 413 full catalog rebuilds to answer 413 yes/no questions, and the catalog is identical every time.
Now it fetches the catalog once and asks 413 cheap questions against it.
Why it matters
remoteWorkspace:setForConnectedTargetsis the second most expensive IPC handler in Orca's main process. Measured live against the packaged app with a probe wrapping all 746ipcMaininvoke handlers:And in a 30-second CPU profile of the same running main process, the repo normaliser reached through
hydrateRepowas the #2 self-time function in the whole process at 0.25%, sitting under exactly this call chain:createRepoRowExecutionHostLookupalsofilters the catalog on each lookup, so the old shape was O(worktrees × repos) allocations per publish on top of the hydration.Measurement
On the reporter's real session — 413 worktrees, 13 repos, 1 connected target:
store.getRepos()calls per publishhydrateRepocalls per publishDeterministic regression guard in
remote-workspace.test.ts— a 12-worktree session, counting catalog reads:The count scales 1:1 with worktree count, so at the reporter's 413 it is 413 → 1.
Correctness
store.getRepos()is a pure read. The handler body between the hoist and the last use is synchronous up to thePromise.all, so no repo mutation can interleave — the old per-worktree reads all returned the same rows anyway.targetForWorktreecompares the resolved connection id againsttargetId, and resolution reads only the repo catalog.Negative user-facing trade-offs
None. This is deleted work, not a traded-off behaviour.
Test plan
src/main/ipc/remote-workspace.test.ts— 1 new test; verified to fail without the fix (12 vs 1).tsc -p config/tsconfig.node.jsonclean;oxlintclean.Update: second commit — resolve each worktree's owning target once per publish, not once per target
Hoisting
store.getRepos()removed the repeat hydration, but the ownership resolution was still repeated once per connected target.targetForWorktreecomputes a connection id from the repo catalog alone — only the final=== targetIddiffers — so exporting to N targets ran the identical resolution N times over every worktree key. And the projection asks the question once per key oftabsByWorktree,activeTabIdByWorktree,lastVisitedAtByWorktreeIdanddefaultTerminalTabsAppliedByWorktreeId, so it is roughly 4-5x the worktree count per target.Resolutions are now memoised for the life of one publish, keyed on
(worktreeId, executionHostId)— both participate in resolution, so both must participate in the key.New regression guard, 6 worktrees x 2 targets:
Combined effect at the reporter's scale (413 worktrees, 13 repos):
store.getRepos()callshydrateRepocallsresolveWorktreeExecutionHostcallsCorrectness is unchanged from above: the memo lives entirely inside one synchronous publish and is discarded afterwards, so a repo added or removed between publishes is picked up exactly as before. NUL is the key separator because it cannot occur in a worktree or host id.
Negative user-facing trade-offs: still none. No cross-call caching, no staleness window, identical exported bytes.
Update: third commit — keep the disconnected path free of the hoisted read
Review caught a real regression the hoist introduced: before this PR the catalog was only read
inside
isTargetWorktree, which never runs when no hydrated target is currently connected. Hoistingit made a zero-connected-target publish pay for a full repo hydration it previously never did —
on a handler that fires ~0.48 times/sec, so the idle/disconnected case is the common one.
A zero-target publish already fell through to
Promise.all([]).filter(...)→[], so the handlernow returns early instead:
That also drops the pre-existing
store.getWorkspaceSession()read on the same path. The returnvalue is unchanged (
[]either way). New regression guard, verified to fail without it(
getReposcalled 1 time, expected 0).Note on the rebase
createRepoRowExecutionHostLookupno longer re-filters the catalog per lookup — #18416 landedthat indexing on
mainafter this PR was opened. That part of the "Why it matters" section above isnow historical; the win claimed here is the removed hydration and the removed repeated
resolution, both of which are orthogonal to #18416 and still measured as stated.
Linked Issue
N/A — no tracked issue. Found by profiling the packaged main process (
ipcMaininvoke-handler probeplus a 30-second CPU profile); the call chain and measurements are in "Why it matters" above.
Visual Proof
N/A— no visual or interaction change. This is a pure main-process optimization: the exportedremote session is byte-for-byte identical, so nothing renders differently.
Testing
pnpm test src/main/ipc/remote-workspace.test.ts— 10 passed. Each of the three perf guards wasverified to fail when its fix is reverted:
getRepos12xgetRepos1xAlso green:
pnpm tc:node,oxlint,oxfmt --check,pnpm run check:code-quality:changed(0 new findings), and
src/shared/worktree-execution-host-resolution.test.ts(15 passed) to confirmthe rebase onto #18416 composes.
Platforms: the change is platform-agnostic (no paths, no shell, no process spawning). Exercised on
macOS. SSH is the subject of the change rather than a caveat — this handler only ever runs for
connected SSH targets, and the SSH execution boundary is untouched: ownership still resolves against
the repo catalog on the execution host, and unresolvable ownership still exports to nobody rather
than guessing (#11163).
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
store.getRepos()is a pure read that was already on this path.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)