Repository navigation
Stop terminal creates from re-reading every workspace's layout - #51271
Conversation
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.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
StatusProblem: 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):
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. |
|
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. |
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.
What Changed
admitPaneToSession/withdrawPaneFromSessionload 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 reusessliceWorkspaceSessionand the share refs from partial layout reloads.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_SCOPESplaces 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.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
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)