Skip to content

perf(startup): overlap catalog/session disk reads with the worktree scan - #9841

Merged
nwparker merged 4 commits into
mainfrom
nwparker/perf-18-concurrent-hydration
Jul 23, 2026
Merged

nwparker merged 4 commits into
mainfrom
nwparker/perf-18-concurrent-hydration

Conversation

@nwparker

@nwparker nwparker commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

What

At startup, App.tsx hydrated the local catalogs and session strictly serially:

list-runtime-session-hosts → fetch-repos → fetch-project-groups → fetch-folder-workspaces → fetch-worktrees → session-get

But only fetch-worktrees and session-get actually depend on repos, 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-hosts now overlaps the repo scan (it reads no repo state).
  • fetch-worktrees, session-get, and an internally-ordered project-groups → folder-workspaces catalog chain run together in a Promise.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-stores still runs only after all three settle, under the existing !cancelled guard. fetchAllWorktrees({hydrationPurge:'defer'}) returns before its folderWorkspaces read (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

  • Verified by reading the store slices that the parallelized steps write disjoint Zustand slices (worktrees → worktreesByRepo/detectedWorktreesByRepo; catalog → projectGroups/folderWorkspaces; folderWorkspacePathStatuses is only ever set to {} at startup), so no shallow-merge set() interleaving can drop an update.
  • session-get (fetchWorkspaceSessionWithRuntimeHostOwners) is a pure read — it never mutates the store; hydration remains a separate synchronous step after the Promise.all.
  • Fail-fast: only session-get's local api.get() can reject; on rejection the outer catch still leaves disk untouched and hydrationSucceeded=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 later await still surfaces any error (and listRuntimeSessionHostIdsForStartup catches internally, returning []).
  • Independent adversarial review (frontier model) traced all of the above against the real code and found no blocker/major/minor/nit.
  • pnpm typecheck:web: clean. workspace-session-host-persistence tests: 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.json or slow-disk/SSH hosts). Startup step telemetry (timeRendererStartupStep) labels are preserved so the overlap is measurable via bench:startup. Effect scales with repo count (longer scan = more fully hidden reads).

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Startup 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 Promise.allSettled, with failures rethrown after all branches finish. Startup routing tests verify the updated ordering and concurrency structure.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed but does not follow the required template and omits several required sections. Reformat it to the repo template and add the missing sections, especially Testing, AI Review Report with cross-platform checks, Security Audit, and Notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main startup performance change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: edcc68ba-bc39-41c9-bd5d-2f1b3079d3d7

📥 Commits

Reviewing files that changed from the base of the PR and between b81e782 and b700b9b.

📒 Files selected for processing (1)
  • src/renderer/src/App.tsx

Comment thread src/renderer/src/App.tsx Resolved
@nwparker
nwparker force-pushed the nwparker/perf-18-concurrent-hydration branch from 003f545 to e850061 Compare July 22, 2026 22:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0e11a09e-2646-4b43-b166-a91dd4ffd8d1

📥 Commits

Reviewing files that changed from the base of the PR and between 003f545 and e850061.

📒 Files selected for processing (2)
  • src/renderer/src/App.tsx
  • src/renderer/src/app-startup-routing.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/App.tsx

Comment on lines +51 to +58
// 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')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
// 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')

nwparker and others added 4 commits July 22, 2026 17:49
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]>
@nwparker
nwparker force-pushed the nwparker/perf-18-concurrent-hydration branch from 7258701 to b876fbe Compare July 23, 2026 00:49
@nwparker
nwparker merged commit 8448557 into main Jul 23, 2026
1 of 2 checks passed
@nwparker
nwparker deleted the nwparker/perf-18-concurrent-hydration branch July 23, 2026 03:41
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant