Skip to content

Stop terminal creates from re-reading every workspace's layout - #51271

Merged
brennanb2025 merged 12 commits into
mainfrom
brennanb2025/perf-terminal-create-off
Nov 28, 2026
Merged

brennanb2025 merged 12 commits into
mainfrom
brennanb2025/perf-terminal-create-off

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

With a lot of workspaces, every new terminal briefly froze the app: before opening one pane, Orca re-read and re-saved the layout of every workspace. Now it reads and saves only the workspace the terminal opens in (plus any workspace that shares something with it), so creating a terminal no longer stalls the app as the fleet grows.

Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​523 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​523
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​415 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​398

What Changed

  • admitPaneToSession / withdrawPaneFromSession load a slice of the session (loadPaneCommandLayout, pane-admission-slice-load.ts) instead of the whole partition: the target workspace, every workspace holding a tab, pane or group id the command names (including a closed-tab record for the tab id), and every workspace the Loader ties to those (shared rows, pane ids, terminals, worktree ids). It reuses sliceWorkspaceSession and the share refs from partial layout reloads.
  • Each build keeps its existing write, narrowed to the slice (pane-admission-change.ts). Window-owned builds rewrote the whole partition from the load; they now rewrite only the records the slice loaded (rewriteSliceRecords), so legacy duplicates the Loader drops still go, and every other record stays as stored. Main-owned builds keep patching only what the command changed, so Loader normalizations stay unwritten, as before.
  • SLICE_FIELD_SCOPES places every stored session field as slice-owned (by workspace, row, pane, closed tab or tab selection) or partition-wide with a reason; a new field fails typecheck until it is placed.
  • It falls back to the whole load whenever only that is exact: legacy surface tombstones, rows saved before pane layouts, more than 64 tied workspaces, or a reminted pane id that ties a workspace outside the slice.

Why

At about 1,900 workspaces, a terminal create spent most of its admission time cloning, loading and re-saving every workspace's layout to change one.

Linked Issue

Tracked internally.

Visual Proof

N/A: no UI change. The app does less work per terminal create.

Testing

  • pane-admission-slice-load.test.ts: in both layout-owner modes, for creates (plain, shared pane id, shared row, new workspace, tab or group id held elsewhere, tab closed elsewhere, beside a folded row), a split and withdrawals (shared row, row stored twice, the slice's only incarnation record), the sliced write returns the same outcome as the whole load and writes the same session (main-owned) or the same layout and changed records (window-owned). Separate cases check that records the slice never loaded (a legacy recovery record, a layout no row owns) survive, and that a selection naming a dropped row is redirected.

  • pane-admission-slice-records.test.ts: every stored field is placed; every per-workspace, per-tab and per-pane field is slice-owned or partition-wide with a reason.

  • pane-admission-slice-load.performance.test.ts: admitting a pane at 200 and 2,000 workspaces loads exactly 1 workspace.

  • Real app at about 1,900 workspaces, before vs after: Linux, main time in pane admission per create 64/29 ms to 11 ms; Windows (Defender on), 26-27 ms to 6.5-8.5 ms per create, with no main-thread gap over 50 ms during creates (before: up to 105 ms). All creates succeeded in both builds.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

Less work per terminal create and per failed-start withdraw: one workspace's load and save instead of the whole partition's, plus a scan of stored ids that does not run the Loader. Nothing new runs anywhere else.

Risk

The riskiest part is the write. Invariant: in window-owned builds the rewrite owns only keys the slice loaded or its save produced, never by prefix, so it cannot delete a record it never loaded. If the tie analysis missed a workspace the Loader links, that workspace could load slightly differently than after a whole load; any case the slice can't prove falls back to the whole load. A plain revert backs it out.

Level: Medium

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Creating or withdrawing a terminal pane loaded and re-saved the layout of every workspace in the partition (about 50 ms per create at 1,900 workspaces). It now loads only the target workspace, the workspaces holding an id the command names, and every workspace the Loader ties to them, then patches only the records the command changed. Any case only a whole load gets exactly right keeps the whole load.
A slice saves only its own records, so a map it empties or first fills was replaced or dropped whole, losing other workspaces' entries (for example every pane's incarnation record after withdrawing the slice's only one).
…'s workspaces

The repair scanned every workspace's rows on each create; only the slice's workspaces can change. A no-op sliced write again returns the stored session so nothing is persisted.
…wned builds

The whole-partition rewrite dropped copies of a removed row that the Loader had hidden in other workspaces; the sliced patch kept them, so the row came back under the other workspace on the next load.
…dow-owned builds

Window-owned builds rewrote the whole partition on admission, which also dropped legacy duplicates the Loader hides. A sliced write now rewrites the records the slice loaded from its save, the same way, and keeps every other record as stored. Main-owned builds keep patching only what the command changed, as before.
…selections

Every stored field is now placed as slice-owned (by workspace, row, pane, closed tab or tab selection) or partition-wide with a reason; the slice rewrites each owned record from its save. Fixes a dropped folded row leaving the saved selections naming it.
… saved

Owning pane and row records by prefix let the rewrite delete legacy recovery records and unowned layouts the slice never loaded; ownership is now the slice's loaded keys plus its save's. A selection under any key that names a row the slice dropped follows the save, as the Loader redirects it.
…vers; check stale records in the slice

The window-owned slice rewrite replaces every slice workspace's row list from its save, so the separate hidden-copy cleanup no longer changed anything. The equivalence test now also checks every record the whole rewrite changed among those the slice loaded.
@brennanb2025
brennanb2025 marked this pull request as ready for review November 28, 2026 05:31
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Pane admission and withdrawal now load pane-command layouts through workspace slicing when the connected set can be established, with whole-session loading as a fallback. Persistence selects a writer based on slice availability and layout ownership. Slice writes update records owned by the slice and preserve other stored records. Tests compare sliced and whole-layout outcomes and check workspace load counts for large sessions.

Merge Risk: Minimal · up to f186f

Terminal creates now load and save only the affected workspaces, falling back to a whole-partition load when the affected set cannot be established exactly. No concrete correctness or performance regression was found, so the change looks ready to merge once CI passes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Stop terminal creates from re-reading every workspace's layout" matches the main change. The PR narrows pane admission (terminal create) to load and save only the target workspace and works…
Description check Passed The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing, Performance, Risk with a level, and the checklist. The Link…
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.
Full details: Title check

Explanation

The title "Stop terminal creates from re-reading every workspace's layout" matches the main change. The PR narrows pane admission (terminal create) to load and save only the target workspace and workspaces tied to it, instead of the whole partition. The title is specific, single-sentence, and does not use vague terms.

Full details: Description check

Explanation

The description follows the repository template. It includes ELI5, What Changed, Why, Linked Issue, Visual Proof (N/A with reason), Testing, Performance, Risk with a level, and the checklist. The Linked Issue says "Tracked internally" without an issue reference, which does not meet the template's requirement to link an actual issue. The AI Disclosure section is empty, and the final pnpm checklist item is unchecked. The Testing and Performance sections are detailed.

Resolution

Consider adding a concrete issue reference under Linked Issue (the template asks for "Fixes #<number>"), filling in the AI Disclosure section if an AI tool was used, and noting the status of pnpm lint, typecheck, test, and build.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f624259-b01a-4f13-8914-4deb4559171a
Commits

Reviewing files that changed from the base of the PR and between a6c4552 and f186f28.

Files selected for processing: 10

  • src/main/persistence/terminal-topology/pane-admission/pane-admission-change.ts
  • src/main/persistence/terminal-topology/pane-admission/pane-admission-slice-load.performance.test.ts
  • src/main/persistence/terminal-topology/pane-admission/pane-admission-slice-load.test.ts
  • src/main/persistence/terminal-topology/pane-admission/pane-admission-slice-load.ts
  • src/main/persistence/terminal-topology/pane-admission/pane-admission-slice-records.test.ts
  • src/main/persistence/terminal-topology/pane-admission/pane-admission-slice-records.ts
  • src/main/persistence/terminal-topology/pane-admission/terminal-pane-admission.ts
  • src/shared/workspace-layout/persistence/workspace-layout-folded-rows.ts
  • src/shared/workspace-layout/persistence/workspace-layout-load-slice.ts
  • src/shared/workspace-layout/persistence/workspace-layout-record-patch.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@brennanb2025

brennanb2025 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Status

Problem: with about 1,900 workspaces, every new terminal (create, split, or withdrawing a pane that failed to start) loaded and re-saved the layout of every workspace on the main process to change one.

Change: it now loads only the workspaces the pane touches and writes back only their records. Shipped builds rewrite those records the way the whole-partition save did, including legacy duplicates the loader drops. Every other record stays as stored. Any case that can't be sliced exactly keeps the whole load.

Verified (before → after, about 1,900 workspaces):

Before After
Admitting one pane (benchmark, shipped build) 49.1 ms 8.6 ms
Admitting one pane (benchmark, main-owned build) 74.5 ms 6.7 ms
Main time in pane admission per create (Linux, real app, 25 creates × 2 runs) 64 / 29 ms 11 / 11 ms
Main long tasks during the agents scenario (Linux) 28.3 ms/s 7.4 ms/s
Layout load/save + admission per create (Windows, Defender on, 18 creates × 2 runs) 27 / 26 ms 6.5 / 8.5 ms
Longest main gap during a create (Windows) up to 105 ms none over 50 ms
  • All terminal creates succeeded in both builds on both platforms.
  • Equivalence tests compare the sliced write against the whole-partition write in both layout modes. They cover shared rows and pane ids, rows stored twice, folded legacy rows and their saved selections, closed tabs, ids held by other workspaces, the first tab of a new workspace, legacy recovery records, and layouts no row owns.
  • A typed table classifies every stored session field as slice-owned or partition-wide, and a test checks that per-workspace, per-tab and per-pane fields are all placed.
  • A perf contract checks that admitting a pane at 200 and 2,000 workspaces loads exactly one workspace.

Not in this PR: each create still scans the stored ids of all workspaces to find the ones tied to the pane (included in the numbers above). A 650–704 ms per-create stall seen once on Windows did not reproduce on the test machine.

QA evidence: real app at about 1,900 workspaces. Linux: 25 terminal creates × 2 runs per build with main-process CPU profiles. Windows: 18 creates × 2 runs per build with Defender on, an event-loop probe and a main-process CPU profile of one create per build. Each create's tab was confirmed in the workspace. No UI change, so there are no screenshots.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Perf scan (head f186f28): no P0/P1. A terminal create, split or failed-start withdraw now does one pass over the stored ids of every workspace plus a slice-sized load and write. Before, it loaded and saved every workspace on the same trigger, so this is a strict subset of the old work. It adds no file or database calls, timers, listeners or retained state. Tie walks stop at 64 workspaces and fall back to the whole load. A perf contract checks one workspace load per admission at 200 and 2,000 workspaces.

@brennanb2025
brennanb2025 merged commit dd30973 into main Nov 28, 2026
140 of 142 checks passed
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