Skip to content

perf(editor): stop rank-only worktree patches and full-state copies from driving owner sweeps - #34705

Merged
nwparker merged 1 commit into
mainfrom
nwparker/owner-route-projection
Oct 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/owner-route-projection

Conversation

@nwparker

@nwparker nwparker commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​106 $\color{#cf222e}{\Huge{\mathbf{−}}}$​19 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​87

Summary

Follow-up to #34691, from the Oct 27 recurrence report on 1.4.243-adhoc.20261028011827. In that report, ten remote sort-order-only worktreesChanged publications blocked the renderer for ~1.7 s, with each task taking 155–188 ms and one timer delayed 1,658 ms. Every rank patch replaced worktreesByRepo, which invalidated editor ownership for all ~250 open files. Each owner lookup also shallow-copied the full ~1,248-property app state.

  1. Narrow route projection. resolveEditorOwnerRoute now builds a projection of only the WorktreeOperationRouteState keys, with focus nulled, instead of {...state, activeWorktreeId: null, ...}. The projection is cached per state object, so one sweep projects once. The projection type lists every key, so a new route input can't be silently left out.
  2. Semantic worktreesByRepo comparison. Editor route inputs now compare worktreesByRepo through a token built from each row's owner fields: id, repoId, hostId and runtimeOwnerEnvironmentId, keeping bucket and row order. Sort-order, unread and activity patches keep the token. As a result, the buffer identity epoch, the buffer reconcile gate and the closed-tab owner-key cache don't invalidate. Real owner, host, membership or order changes still do.
  3. selectWorktreesByRepo, selectFolderWorkspaces and selectDetectedWorktreesByRepo are now generic, so route-state projections can read through them. Existing callers get the same return types.

This is a free win: routing output is unchanged and only redundant work is removed. A sub-agent reviewed the change and found no reads outside the projected keys and row fields on these paths.

Proof

Benchmark at the reported census: 251 edit tabs, 171 worktrees, ~1,600 worktree rows, real store, buffer middleware and controller. Before = main, which already includes #34691; after = this branch.

Update Owner lookups (before → after) ms/update (before → after)
Rank-only worktree patch 251 → 0 1.47 → 0.13
Catalog timestamp-only update 251 → 251 1.16 → 0.25
Owner key × 251 files — 1.33 → 0.24

The test store has 198 properties, while the reported app state had 1,248. The spread cost grows with property count, so production savings should be larger. The reporter measured 24.6 ms → 1.6 ms for the same comparison on real data, with 0/249 key mismatches.

The new regression test asserts that a rank-only patch performs zero owner lookups and that an owner change still re-resolves.

Not in scope: batching order publications across project buckets (P1-C), runtime-environment timestamp churn, diff/chat geometry, and host retry backoff.

Testing

  • pnpm check:changed --maxWorkers=2: everything passed except formatting, which was then fixed
  • Owner-route, editor-model-owner, workspace-record selector and closed-editor suites pass

…rom driving owner sweeps

resolveEditorOwnerRoute spread the full app state on every owner lookup;
project only route inputs, cached per state. Compare worktreesByRepo by its
owner fields so sort-order/unread/activity patches skip editor ownership
invalidation.
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