Repository navigation
perf(renderer): index GitHub resume lookups - #13698
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe change adds a cached GitHub repository lookup index with ID, path, and combined lookup methods. GitHub repository and worktree resolution now uses memoized indexes and supports missing collections. Refresh logic skips unnecessary work, reuses resolved repositories, and uses indexed iteration. Tests cover duplicate IDs, sparse matches, cache behavior, bounded identity reads, runtime dispatch, and inactive refresh views. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1eb6f9c2-5d90-4279-8075-f2da2b007622
📒 Files selected for processing (4)
src/renderer/src/store/slices/github-repo-lookup-index.test.tssrc/renderer/src/store/slices/github-repo-lookup-index.tssrc/renderer/src/store/slices/github.test.tssrc/renderer/src/store/slices/github.ts
| const duplicateCandidates = mockApi.gh.enqueuePRRefresh.mock.calls | ||
| .map(([call]) => call.candidate) | ||
| .filter((candidate) => candidate.repoId === repoId) | ||
| expect(duplicateCandidates).toHaveLength(2) | ||
| expect(duplicateCandidates).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| repoPath: '/first', | ||
| connectionId: 'first', | ||
| executionHostId: 'ssh:first' | ||
| }), | ||
| expect.objectContaining({ | ||
| repoPath: '/first', | ||
| connectionId: 'first', | ||
| executionHostId: 'ssh:first' | ||
| }) | ||
| ]) | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Does Vitest expect.arrayContaining require duplicate expected elements to match distinct received elements?
💡 Result:
No, Vitest's expect.arrayContaining does not require duplicate expected elements to match distinct received elements [1][2]. The expect.arrayContaining matcher functions by verifying that the received array is a superset of the expected array [1][2]. It checks whether each element in the expected array exists somewhere in the received array; it does not perform a one-to-one mapping or verify counts, nor does it enforce that multiple instances of an element in the expected array must correspond to separate, distinct instances in the received array [1][2]. In practice, if you have an expected array like ['a', 'a'] and a received array like ['a', 'b', 'c'], expect.arrayContaining(['a', 'a']) will evaluate to true because 'a' is present in the received array, satisfying the subset requirement for each expected item individually [1][2]. This behavior is consistent with Jest, upon which Vitest's expect implementation is based [3][4][5]. If you require an exact match that accounts for both quantity and value (i.e., verifying the frequency of elements), expect.arrayContaining is not the appropriate tool, and you should instead use other matchers or a custom validation approach [6][7].
Citations:
- 1: https://main.vitest.dev/guide/learn/matchers
- 2: https://vitest.dev/api/expect.html
- 3: https://jestjs.io/docs/29.7/expect
- 4: https://jestjs.io/docs/next/expect
- 5: https://github.com/jestjs/jest/blob/main/docs/ExpectAPI.md
- 6: https://stackoverflow.com/questions/40135684/is-there-an-array-equality-match-function-that-ignores-element-position-in-jest
- 7: https://stackoverflow.com/questions/57001262/jest-expect-only-unique-elements-in-an-array
🏁 Script executed:
#!/bin/sh
set -eu
file='src/renderer/src/store/slices/github.test.ts'
printf '%s\n' '--- relevant test context ---'
sed -n '5760,5840p' "$file"
printf '%s\n' '--- Vitest references ---'
rg -n '"vitest"|vitest@|expect\.arrayContaining' package.json package-lock.json pnpm-lock.yaml yarn.lock "$file" 2>/dev/null | head -80Repository: stablyai/orca
Length of output: 2989
Tighten the duplicate-ID assertion so it checks every candidate.
expect.arrayContaining does not require duplicate expected entries to match distinct received elements. With toHaveLength(2), the second candidate could still contain repoPath: '/second' and connectionId: 'second' without failing this test. Assert the expected fields on each candidate.
…changed Every eviction helper already returns its input reference untouched when it evicts nothing, so the opening sweep in refreshAllGitHub can compare identities and return the previous state. Window resume then stops waking every store subscriber on a no-op sweep. Folds in the remaining unique optimization from #13711, which this PR supersedes on the lookup-indexing side. Co-authored-by: Orca <[email protected]>
Superseding #13711 — folded in its unique optimization#13711 and this PR overlap on Both carry the identical
The dispatch-path gap is the substantive one. Running #13698's scale tests against #13711 and doubling
#13711 only de-duplicated lookups within The one thing #13711 had that this PR didn't: it returned the previous state from the opening cache sweep when nothing changed. Every eviction helper already returns its input reference untouched on a no-op ( Correctness reviewThe highest-risk surface here is
Local: 199 focused tests, 2431 renderer store tests, Follow-up (not blocking)
|
* perf(renderer): index GitHub resume lookups * perf(renderer): skip the resume cache sweep publication when nothing changed Every eviction helper already returns its input reference untouched when it evicts nothing, so the opening sweep in refreshAllGitHub can compare identities and return the previous state. Window resume then stops waking every store subscriber on a no-op sweep. Folds in the remaining unique optimization from stablyai#13711, which this PR supersedes on the lookup-indexing side. Co-authored-by: Orca <[email protected]> --------- Co-authored-by: Orca <[email protected]>
Summary
ELI5
When Orca came back to the foreground, it repeatedly walked the whole project list to answer questions like “which project owns this workspace?” With many remote projects, it could reread the same list millions of times. This gives Orca a temporary address book: each project/workspace is recorded once, then later lookups go straight to the answer. If no PR or issue badges are visible, Orca skips the walk entirely.
Why
The app calls
refreshAllGitHub()whenever the window becomes visible. The old path used nested.find()scans during candidate collection, runtime routing, PR/issue fetch setup, request-head lookup, and response handling. Runtime-owned repos under PR-status grouping process every stale candidate, so 1,200 repos/worktrees produced quadratic renderer work during foreground resume.Measurement
Node v24.18.0, 1,200 repos + 1,200 worktrees, 15 warmups, median of 31 samples, 5 invocations per sample. The matched synchronous kernel covers candidate collection, runtime-owner routing, fetch repo selection, runtime repo routing, and request-head lookup.
That is about 42.1x faster for the measured lookup work. Deterministic scale tests also wait for all 128 runtime PR/issue responses and enforce linear identity-read bounds. With decorations hidden, the test proves zero repo/worktree identity reads while cache cleanup still runs.
Behavior and safety
Array.findfirst-match behavior for duplicate repo IDs and paths, including ID-or-path precedence across local, SSH, and runtime hostsWeakMapownership does not retain superseded snapshotsValidation
refreshAllGitHubdescribe: 12 passedgit diff --checkpassedFull-suite command used the intended release baseline:
ORCA_CROSS_VERSION_BASELINE_REF=v1.4.177 pnpm testResidual risk
The benchmark isolates synchronous renderer lookup work rather than packaged visibility-to-idle latency. No real SSH sleep/resume smoke or heap snapshot was taken; deterministic scaling and copy-on-write invalidation tests cover the changed contract.