Skip to content

perf(renderer): reuse folder connection inference across store writes - #34800

Merged
OrcaWin merged 4 commits into
mainfrom
OrcaWin/perf-folder-connection-cache
Oct 29, 2026
Merged

OrcaWin merged 4 commits into
mainfrom
OrcaWin/perf-folder-connection-cache

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​33
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​48 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​47

ELI5

Folder tab bars repeatedly search the same repositories to identify their connection. Reuse that answer until the ownership catalogs change.

What Changed

Retained folder-workspace tab strips resolve their SSH ownership on every store publication, including unrelated terminal title and editor writes. For folders with inherited ownership this repeatedly walks the folder catalog, project-group subtree, and repository list on the renderer thread. Cache the existing resolver's answer by the three immutable catalog arrays so these reads reuse their result until ownership inputs change.

Evidence

The regression test subscribes to a vanilla store and calls the production getConnectionIdFromState route for two folder workspaces across 50 unrelated publications. Property getters count actual repository classifications inside host inference; the test does not replace the resolver.

Repository count Before After, warm catalog
100 10,000 classifications 0
1,000 100,000 classifications 0

Both count assertions fail on the base implementation with exactly the before counts. This proves removal of repeated renderer work; it does not claim a measured end-to-end frame-time improvement.

Correctness and resource lifetime

  • Reuse the same shared host resolver and preserve SSH target / local null / missing-or-ambiguous undefined results, including paired hosts' nested SSH targets.
  • Changing any folder, project-group, or repository array computes a fresh answer. Interleaved old and new snapshots remain independent.
  • All catalog keys are weak. Answers contain only host identity, and missing folder IDs are not cached, so arbitrary lookup misses cannot grow a map. Entries in a catalog combination are bounded by its existing folder IDs.
  • This is a renderer-local optimization; there is no wire-format, host-version, path-normalization, provider, or mobile contract change. Existing macOS/Linux/Windows and remote ownership rules continue to run on cache misses.

Validation

  • Targeted connection-context, shared folder-host, terminal-pane host-state, and runtime terminal-drop ownership tests: 63 passed after the cache-boundary correction.
  • Added invalidation controls cover repository owner changes, project-group changes, folder host pins, disappearance, local resolution, ambiguity, nested runtime SSH, and old-snapshot reads.
  • Incomplete catalog snapshots delegate directly to the existing lazy resolver before cache access. Complete catalogs use the weak cache. The unchanged runtime-folder terminal-drop ownership control passes with an omitted project-group catalog.
  • Required aggregate on clean head 08c807b72ce, pinned base 66e2d398278, disk-backed TMPDIR, background launch and two workers: 20/21 checks passed; exited 1 after 3139.7s. The unit task failed after 3126.1s with repeated EACCES: permission denied, posix_spawn errors for the pinned test runtime executable.
  • The runtime executable and path are executable now, and a direct version probe succeeds. This does not establish the transient failure's cause. The runner did not publish a fresh results cache: its cache timestamp predates this attempt, and 1377 earlier output lines were truncated. Complete unit totals and any earlier assertion failures are therefore unverified. The aggregate remains failed.
  • The previous aggregate also passed 20/21 checks, but its unit stage failed after 6650.5s with /tmp inode exhaustion and missing temporary modules. No source, assertion, timeout or pass-cache stamp was changed to bypass either result.
  • Final unchanged-head confirmation after the executable recovered passed all four focused suites: 63/63 tests in 12.53s, using the same pinned runtime, disk-backed TMPDIR, background launch and two workers. This verifies the direct connection/host/terminal-drop controls; it does not replace the failed aggregate.

Visual Proof

N/A — the rendered controls and interactions are unchanged; evidence counts eliminated computation at production selectors.

Review

Reviewed for cache invalidation, ownership, retention and meaningful-update controls. No transport or platform-specific API change. Only Linux was executed locally; cross-platform ownership cases use fixtures.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer source or assets copied.

Checklist

  • Focused change with before/after regression evidence.
  • Automated correctness and eliminated-work checks included.
  • Cross-platform, remote, mobile and folder-workspace implications considered.
  • Required changed-file gate passed.

…read check

Drop the zustand store wrapper and duplicate 1,000-repo case, and use a neutral fixture path.
The invalidation and tri-state test guards observable behavior; the getter
read counter only pinned the cache implementation.
@OrcaWin
OrcaWin marked this pull request as ready for review October 29, 2026 00:55
@OrcaWin
OrcaWin enabled auto-merge (squash) October 29, 2026 00:55
@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 1 minute.

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: 4eaa276c-f28b-4ef1-98d0-f121a3b0ef5f
Commits

Reviewing files that changed from the base of the PR and between eac5699 and db54f3c.

Files selected for processing: 2
  • src/renderer/src/lib/connection-context.test.ts
  • src/renderer/src/lib/folder-workspace-connection.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.

@OrcaWin
OrcaWin merged commit 1775410 into main Oct 29, 2026
32 checks passed
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The optimization is limited to renderer folder-workspace ownership lookups.

This appears safe to merge, with a non-blocking gap in tests for the performance benefit.

Findings

  1. P2 Cache reuse goes untested ▶

Summary

Reuses folder connection answers across reads with the same folder, project-group, and repository arrays.

  • Folder connection lookups reuse answers while ownership catalogs stay the same.

Reviews (1) · Last reviewed commit: "test(renderer): drop folder connection r..." · Reviewed by Greptile

Comment on lines +716 to +724
it('invalidates folder connection inference for each catalog slice and preserves tri-state answers', () => {
const key = folderWorkspaceKey('folder-workspace-1')
const state: ConnectionContextState = {
folderWorkspaces: [makeFolderWorkspace()],
projectGroups: [makeProjectGroup()],
repos: [makeRepo({ id: 'repo-1', projectGroupId: 'group-1', connectionId: 'ssh-1' })],
worktreesByRepo: {}
}
expect(getConnectionIdFromState(state, key)).toBe('ssh-1')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Cache reuse goes untested

The added test would still pass if getFolderWorkspaceConnectionId called resolveFolderWorkspaceHost every time. It checks answers and changed catalogs, but not whether repeated folder lookups skip repository scans.

Add a test that counts repository reads across repeated calls and unrelated store writes, then confirms that changing a catalog triggers fresh work. This would protect the performance benefit this PR introduces.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

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