Skip to content

perf(editor): compare worktree owner rows by identity instead of a per-write JSON signature - #35824

Merged
nwparker merged 2 commits into
mainfrom
perf/editor-buffer-route-recheck
Oct 29, 2026
Merged

nwparker merged 2 commits into
mainfrom
perf/editor-buffer-route-recheck

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

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

ELI5

Every time a workspace's activity, unread or sort state changes, Orca checks whether the change affects which workspace owns each open editor file. That check rebuilt a text summary of every worktree on each update. Now it compares only the rows that actually changed.

What Changed

src/renderer/src/lib/worktree-owner-rows-token.ts

  • Before: each new worktreesByRepo map produced a JSON string built from every worktree's owner fields, which was then compared with the previous string.
  • After: the new map is compared with the last one it saw, by identity. Buckets and rows that are the same object are skipped. Only rows that changed have their owner fields compared: id, repoId, hostId ?? null, runtimeOwnerEnvironmentId ?? null. A change in bucket or row order still counts as a change.
  • The last baseline is held through a WeakRef, so a removed catalog isn't kept in memory. If the baseline has been garbage-collected, the next map gets a fresh token, which just means one extra conservative re-check.

There are two consumers, and both get faster: the editor-buffer record middleware (editor-buffer-identity-cache.ts) and StructuredAgentSessionStatusBridge.

Why

Micro-benchmark with 200 open files, 300 worktrees and 1000 activity writes. The machine was heavily loaded, so the ratios matter more than the absolute numbers.

before after
Owner-route check per activity write 38–73 µs 0.8 µs

Where this came from

This was one of the smaller contributors to the renderer stalls reported in #35660. The main cause there was the body:has() rule from #33799, fixed by #34932.

Linked Issue

Refs #35660

Visual Proof

N/A: performance-only change with no visual or interaction difference.

Testing

  • New worktree-owner-rows-token.test.ts checks that:

    • a cloned row keeps the token
    • hostId: undefined is treated the same as missing
    • a hostId change gets a new token
    • a reorder gets a new token
  • Targeted editor, buffer-lifecycle, owner-key and native-chat suites pass. The one failure, native-chat-composer-draft-store.test.ts, also fails on unmodified main.

  • pnpm check:changed --maxWorkers=2: 22/22 checks pass.

  • Adversarial reviews:

    • Opus: a differential fuzz against the old implementation over 10k iterations found 0 mismatches.
    • Codex (gpt-6.1-sol, xhigh): a 20k-transition differential found 0 mismatches. A real V8 GC run confirmed the retention fix. Its earlier finding that the baseline was strongly retained is fixed in this PR.
  • Platform: macOS. The change is pure renderer logic with no platform branches. Folder workspaces come from folderWorkspaces, which this change doesn't touch. Remote hosts are covered by the host and runtime-owner fields.

  • I manually tested these changes locally

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

🤖 Generated with Claude Code

… signature

Activity/unread/rank patches to worktreesByRepo still stringified every
worktree's owner fields on each write to decide the route token. Walk
buckets and rows identity-first against the last tokenized map instead;
same order-sensitive owner-field semantics, no per-write allocation.

300 worktrees, 200 open files: route check per activity write ~40-70us -> ~0.8us.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 51 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 89379514-4010-48eb-b8ba-9cdefab18040
Commits

Reviewing files that changed from the base of the PR and between 21fdaee and 5c4dc47.

Files selected for processing: 2
  • src/renderer/src/lib/worktree-owner-rows-token.test.ts
  • src/renderer/src/lib/worktree-owner-rows-token.ts
  • 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

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

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

Replaces the JSON signature in worktreeOwnerRowsTokenOf with an identity-first comparison.

  • Unchanged worktree owners reuse a token, so frequent updates skip extra ownership checks.

No actionable issues found. nwparker explicitly acknowledges that a collected baseline may cause one extra conservative owner check.

Reviews (1) · Last reviewed commit: "perf(editor): hold the last owner-rows b..." · Reviewed by Greptile

@nwparker
nwparker merged commit abbea99 into main Oct 29, 2026
40 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