Repository navigation
perf(editor): stop rank-only worktree patches and full-state copies from driving owner sweeps - #34705
Merged
Merged
Conversation
…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.
This was referenced Oct 28, 2026
7 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #34691, from the Oct 27 recurrence report on
1.4.243-adhoc.20261028011827. In that report, ten remote sort-order-onlyworktreesChangedpublications blocked the renderer for ~1.7 s, with each task taking 155–188 ms and one timer delayed 1,658 ms. Every rank patch replacedworktreesByRepo, which invalidated editor ownership for all ~250 open files. Each owner lookup also shallow-copied the full ~1,248-property app state.resolveEditorOwnerRoutenow builds a projection of only theWorktreeOperationRouteStatekeys, 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.worktreesByRepocomparison. Editor route inputs now compareworktreesByRepothrough a token built from each row's owner fields:id,repoId,hostIdandruntimeOwnerEnvironmentId, 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.selectWorktreesByRepo,selectFolderWorkspacesandselectDetectedWorktreesByRepoare 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.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