Repository navigation
perf(startup): overlap catalog/session disk reads with the worktree scan - #9841
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughStartup hydration now starts runtime session host discovery without blocking local repository loading. Project groups and folder workspaces are grouped into a local catalog chain, while worktree retrieval, session restoration using runtime host IDs, and local catalog loading execute concurrently through 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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 |
003f545 to
e850061
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0e11a09e-2646-4b43-b166-a91dd4ffd8d1
📒 Files selected for processing (2)
src/renderer/src/App.tsxsrc/renderer/src/app-startup-routing.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- src/renderer/src/App.tsx
| // Guard the concurrency itself: fetch-worktrees, the session read, and the local catalog chain must | ||
| // be joined in a single Promise.all so the two disk reads hide behind the O(repos) worktree scan. | ||
| const joinStart = startupBlock.indexOf('await Promise.all([') | ||
| expect(joinStart).toBeGreaterThan(hydrateUiIndex) | ||
| const joinBlock = startupBlock.slice(joinStart) | ||
| expect(joinBlock).toContain("timeRendererStartupStep('fetch-worktrees'") | ||
| expect(joinBlock).toContain('sessionReadPromise') | ||
| expect(joinBlock).toContain('localCatalogChain') |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Bound the concurrency assertion to the actual Promise.all array.
startupBlock.slice(joinStart) includes everything after the join, so later references to sessionReadPromise or localCatalogChain can satisfy these checks even if they are removed from the Promise.all operands. Slice through the closing ]) (or parse the call) before asserting membership.
Proposed fix
const joinStart = startupBlock.indexOf('await Promise.all([')
expect(joinStart).toBeGreaterThan(hydrateUiIndex)
- const joinBlock = startupBlock.slice(joinStart)
+ const joinEnd = startupBlock.indexOf('])', joinStart)
+ expect(joinEnd).toBeGreaterThan(joinStart)
+ const joinBlock = startupBlock.slice(joinStart, joinEnd)
expect(joinBlock).toContain("timeRendererStartupStep('fetch-worktrees'")
expect(joinBlock).toContain('sessionReadPromise')
expect(joinBlock).toContain('localCatalogChain')📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Guard the concurrency itself: fetch-worktrees, the session read, and the local catalog chain must | |
| // be joined in a single Promise.all so the two disk reads hide behind the O(repos) worktree scan. | |
| const joinStart = startupBlock.indexOf('await Promise.all([') | |
| expect(joinStart).toBeGreaterThan(hydrateUiIndex) | |
| const joinBlock = startupBlock.slice(joinStart) | |
| expect(joinBlock).toContain("timeRendererStartupStep('fetch-worktrees'") | |
| expect(joinBlock).toContain('sessionReadPromise') | |
| expect(joinBlock).toContain('localCatalogChain') | |
| // Guard the concurrency itself: fetch-worktrees, the session read, and the local catalog chain must | |
| // be joined in a single Promise.all so the two disk reads hide behind the O(repos) worktree scan. | |
| const joinStart = startupBlock.indexOf('await Promise.all([') | |
| expect(joinStart).toBeGreaterThan(hydrateUiIndex) | |
| const joinEnd = startupBlock.indexOf('])', joinStart) | |
| expect(joinEnd).toBeGreaterThan(joinStart) | |
| const joinBlock = startupBlock.slice(joinStart, joinEnd) | |
| expect(joinBlock).toContain("timeRendererStartupStep('fetch-worktrees'") | |
| expect(joinBlock).toContain('sessionReadPromise') | |
| expect(joinBlock).toContain('localCatalogChain') |
00fce0c to
7258701
Compare
App.tsx hydrated repos, project-groups, folder-workspaces, worktrees, then
session-get strictly serially, even though only worktrees depends on repos.
Once repos is loaded, run fetch-worktrees, session-get, and the (internally
ordered) local project-group/folder-workspace catalog chain concurrently so
the two disk reads hide behind the O(repos) worktree git scan (the startup
long pole). list-runtime-session-hosts now overlaps the repo scan too.
Ordering preserved: repos before worktrees/session; project-groups before
folder-workspaces; hydrate-session-stores still runs only after all settle.
fetchAllWorktrees({hydrationPurge:'defer'}) returns before its folderWorkspaces
read, so it needs no catalog ordering at startup.
Co-authored-by: Orca <[email protected]>
Address CodeRabbit review: awaiting runtimeHostsPromise before the Promise.all made fetch-worktrees + the catalog chain wait on list-runtime-session-hosts, even though only session-get needs the host ids. Chain session-get off the host promise inside the Promise.all instead, so the worktree scan and catalog reads start immediately and the host-list IPC only gates session-get. Co-authored-by: Orca <[email protected]>
The #18 startup change runs worktrees/session-get/catalog concurrently in a single Promise.all, so the guard's old serial folders<worktrees assertion (and its session-get slice terminator) no longer describe the code. Assert the real invariants: UI hydrates before any local read, the catalog chain stays ordered, worktrees+session start after repos, and all three are joined in one Promise.all. Co-authored-by: Orca <[email protected]>
…an't race in-flight tasks The concurrent worktrees/session/catalog join used fail-fast Promise.all, so a fast rejection from one branch dropped into the catch/recovery path (which reconnects terminals and flips readiness) while a sibling hydration task was still in flight and mutating catalog/worktree state — a race the old serial flow could not hit. Use Promise.allSettled and surface the first rejection only after all three settle, so recovery still triggers but nothing is left writing to the store. Guard test updated. Co-authored-by: Orca <[email protected]>
7258701 to
b876fbe
Compare
…can (stablyai#9841) * perf(startup): overlap catalog/session disk reads with the worktree scan App.tsx hydrated repos, project-groups, folder-workspaces, worktrees, then session-get strictly serially, even though only worktrees depends on repos. Once repos is loaded, run fetch-worktrees, session-get, and the (internally ordered) local project-group/folder-workspace catalog chain concurrently so the two disk reads hide behind the O(repos) worktree git scan (the startup long pole). list-runtime-session-hosts now overlaps the repo scan too. Ordering preserved: repos before worktrees/session; project-groups before folder-workspaces; hydrate-session-stores still runs only after all settle. fetchAllWorktrees({hydrationPurge:'defer'}) returns before its folderWorkspaces read, so it needs no catalog ordering at startup. Co-authored-by: Orca <[email protected]> * perf(startup): don't serialize the worktree scan behind host discovery Address CodeRabbit review: awaiting runtimeHostsPromise before the Promise.all made fetch-worktrees + the catalog chain wait on list-runtime-session-hosts, even though only session-get needs the host ids. Chain session-get off the host promise inside the Promise.all instead, so the worktree scan and catalog reads start immediately and the host-list IPC only gates session-get. Co-authored-by: Orca <[email protected]> * test(startup): assert concurrent hydration graph in source-order guard The stablyai#18 startup change runs worktrees/session-get/catalog concurrently in a single Promise.all, so the guard's old serial folders<worktrees assertion (and its session-get slice terminator) no longer describe the code. Assert the real invariants: UI hydrates before any local read, the catalog chain stays ordered, worktrees+session start after repos, and all three are joined in one Promise.all. Co-authored-by: Orca <[email protected]> * fix(startup): join concurrent hydration with allSettled so recovery can't race in-flight tasks The concurrent worktrees/session/catalog join used fail-fast Promise.all, so a fast rejection from one branch dropped into the catch/recovery path (which reconnects terminals and flips readiness) while a sibling hydration task was still in flight and mutating catalog/worktree state — a race the old serial flow could not hit. Use Promise.allSettled and surface the first rejection only after all three settle, so recovery still triggers but nothing is left writing to the store. Guard test updated. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
What
At startup,
App.tsxhydrated the local catalogs and session strictly serially:But only
fetch-worktreesandsession-getactually depend onrepos, and the O(repos) worktree git scan is the startup long pole. This change runs the mutually-independent steps concurrently once repos is loaded:list-runtime-session-hostsnow overlaps the repo scan (it reads no repo state).fetch-worktrees,session-get, and an internally-orderedproject-groups → folder-workspacescatalog chain run together in aPromise.all, so the two disk reads (session JSON, catalog) hide behind the worktree git scan.Ordering invariants preserved: repos before worktrees/session; project-groups before folder-workspaces (folder merges
s.projectGroups);hydrate-session-storesstill runs only after all three settle, under the existing!cancelledguard.fetchAllWorktrees({hydrationPurge:'defer'})returns before itsfolderWorkspacesread (the purge guard), so it needs no catalog ordering at startup.ELI5
Orca used to unpack its moving boxes one at a time — even boxes that had nothing to do with each other — while you waited at a blank screen. The slowest box is scanning all your repos. Now it opens the other boxes (your saved tabs, your project groups) at the same time as that slow scan, so they're already done by the time the scan finishes. Same result, less waiting — and it helps more the more repos you have.
Proof of zero regression
worktreesByRepo/detectedWorktreesByRepo; catalog →projectGroups/folderWorkspaces;folderWorkspacePathStatusesis only ever set to{}at startup), so no shallow-mergeset()interleaving can drop an update.session-get(fetchWorkspaceSessionWithRuntimeHostOwners) is a pure read — it never mutates the store; hydration remains a separate synchronous step after thePromise.all.session-get's localapi.get()can reject; on rejection the outer catch still leaves disk untouched andhydrationSucceeded=false(session writer stays gated on ready + hydration-success). The concurrently-running catalog/worktree steps had already run before session-get in the old serial order too.runtimeHostsPromise.catch(() => {})marks an early rejection handled without changing propagation; the laterawaitstill surfaces any error (andlistRuntimeSessionHostIdsForStartupcatches internally, returning[]).pnpm typecheck:web: clean.workspace-session-host-persistencetests: 13/13 pass.Proof of perf improvement
The change removes the session-JSON read and the project-group/folder-workspace catalog reads from the startup critical path by overlapping them with the worktree git scan they don't depend on. Net saving ≈ the sum of the overlapped disk-read durations (tens of ms typically; larger for big
session.jsonor slow-disk/SSH hosts). Startup step telemetry (timeRendererStartupStep) labels are preserved so the overlap is measurable viabench:startup. Effect scales with repo count (longer scan = more fully hidden reads).Made with Orca 🐋