Repository navigation
perf: index editor ownership and restored workspace projections - #19444
Conversation
|
Warning Review limit reachedNext included review available in 26 minutes. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (7)
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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This PR replaces three O(n²) scans in editor-session hydration with indexed lookups, with parity + scaling regression coverage. Reviewed the new index, the two extracted projection helpers, their call sites, and all three test suites.
LegacyHydratedEditorFileIndex— aMap-backed replacement for the linearresolveLegacyHydratedEditorFileId/ duplicate-owner scan inhydrate-editor-session.ts, keyed on(filePath, owner)and(id → owners).resolveHydratedEditorFileSelection— indexes restored files once and resolves the active file + per-worktree active file map, replacing thefind/somefallback and migration logic.resolveHydratedEditorFrontmatter— resolves hidden-frontmatter overrides with a smaller-side scan across migration maps, replacing the per-override × per-migration fan-out.- Parity + scaling tests — 7 new tests that run the fast path against a faithful reference of the old logic (Windows paths, remote owners, duplicates, blank IDs) and assert near-linear read counts (2,000 files / 1,000 workspaces).
I traced the new logic against the removed code in hydrate-editor-session.ts and hydrated-editor-file-ids.ts and confirmed behavioral equivalence: owner-key composition (JSON.stringify([worktreeId, runtimeOwnerKey(...)])) matches isSameEditorOwner; the occupied.size > 1 || !occupied.has(owner) gate matches isEditorFileIdOccupiedByOtherOwner for both the same-owner and other-owner cases; firstFileId matches openFiles.find(...); and usedOpenFileIds is identical to the old Set(openFiles.map(f => f.id)). The new tests pass, pnpm run typecheck:web passes, and the changed-code quality gate reports zero new findings.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

ELI5
When Orca restarts, it reopens the files you had open. Before it can, it has to make sure no two restored tabs end up sharing the same identity — the same file can legitimately be open twice, once against your local checkout and once against a remote machine, and those must stay separate tabs. The old code answered that by comparing each file it restored against every file it had already restored. With a handful of tabs that is invisible. With a couple of thousand restored tabs it turns into millions of comparisons, and the window sits empty while it grinds through them.
This change keeps a lookup table as it restores instead. "Is there already a tab for this path, owned by this workspace and this machine?" is now answered in one step rather than by rescanning the whole list. The same trick is applied to two related passes that ran right after it: choosing which tab should be focused in each workspace, and restoring which Markdown files had their frontmatter block hidden.
Nothing about what gets restored changes — same tabs, same focused tab, same unsaved edits, same hidden-frontmatter choices, same handling of sessions saved by older versions. Only the way they are looked up changes. The new tests run the fast lookup and the old line-by-line logic side by side over thousands of generated cases, including Windows paths, remote-owned files, duplicates and blank IDs, and assert the two always agree.
What Changed / Why
This PR contains only this focused change and its regression coverage. It targets
mainindependently of the other desktop audit PRs. Measurements describe operation/allocation reductions, not end-to-end latency gains.Linked Issue
User-requested desktop performance audit; no issue supplied.
Visual Proof
N/A — no visual design change. Behavior and performance invariants are checked by automated regression tests.
Testing
pnpm tcpassed on this branch.git diff --cached --checkpassed.ORCA_BACKGROUND_LAUNCH=1. No visible test window was launched.Test files:
src/renderer/src/store/slices/editor-hydration-scaling.test.tssrc/renderer/src/store/slices/editor/file-ids/hydrated-editor-file-index.test.tssrc/renderer/src/store/slices/editor/file-ids/hydrated-editor-projections.test.tsAgent skill upstream boundary
Checklist