Skip to content

perf(renderer): cache structured chat presence by snapshot identity - #34774

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/perf-chat-presence-cache
Oct 28, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/perf-chat-presence-cache

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​66
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​35 $\color{#cf222e}{\Huge{\mathbf{−}}}$​23 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​12

ELI5

Unrelated terminal title updates repeatedly recalculate whether every visible workspace has an awake chat. Reuse the answer until that workspace's chats or sleep state changes.

What Changed

Unrelated terminal pane-title writes currently make each mounted sidebar, parent-picker, and Cmd+J status reader rescan its structured chat bucket. Each visited chat computes structuredAgentSessionPaneKey, which runs synchronous JavaScript SHA-256, before Zustand/React equality can suppress an unchanged status render.

Cache the awake/unknown predicates by the exact immutable tab bucket and sleep-map snapshots. Both keys use WeakMaps, so the cache introduces no subscription, timer, IPC, or strong historical ownership. Missing sleep state uses a shared frozen empty snapshot. Cold reads and actual tab/sleep changes still recompute the predicate; explicit sleep, explicit wake, unknown, working, and done priorities are preserved.

Why

The relevant writers replace published inputs: tab create/close/move/drop/patch, hydration/reconciliation, title batches, local layout frames, and remote tab projection replace changed buckets; batch writers only mutate private record copies. setStructuredChatSleptAt replaces its map on an actual change.

This shares results across mounted readers and unrelated store updates without adding a new owner or invalidation subscription. Checking only React render counts misses the synchronous work performed before equality checks.

Linked Issue

N/A — internal performance audit; no pre-existing issue.

Visual Proof

N/A — status values and interactions are unchanged; this removes repeated selector work.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Measured with the existing live Zustand store + mounted production reader benchmark, using a real setRuntimePaneTitle action after warm-up. The fixture has explicitly slept chats, so the false predicate visits the full bucket; an awake/unknown chat can short-circuit earlier on the base:

Mounted reader route Workspaces × structured chats Before: tab visits / SHA-256 calls After
Sidebar 20 × 10 200 / 200 0 / 0
Sidebar 20 × 100 2,000 / 2,000 0 / 0
Parent picker 20 × 10 200 / 200 0 / 0
Parent picker 20 × 100 2,000 / 2,000 0 / 0
Cmd+J palette 20 × 10 800 / 800 0 / 0
Cmd+J palette 20 × 100 8,000 / 8,000 0 / 0
Sidebar / picker 87 × 2 174 / 174 0 / 0
Sidebar / picker 870 × 2 1,740 / 1,740 0 / 0
Cmd+J palette 87 × 2 696 / 696 0 / 0
Cmd+J palette 870 × 2 6,960 / 6,960 0 / 0

These are deterministic operation counts from Linux, Node 26.8.1, Vitest/happy-dom development tests against base 32a50856ac388a419ffa18b2295a76d1744f7ec5. Palette counts include its four selector/snapshot visits per reader. This establishes removed synchronous renderer work; it does not establish packaged Electron frame latency, CPU, or heap savings. No new runtime instrumentation or machine-dependent timing threshold is shipped.

  • Strengthened production-reader regression test fails on the base implementation (six failures, e.g. 200/174/800/696 calls where zero is required) and passes with the cache.
  • Focused tests: 4 files / 34 tests passed, covering actual sleep/wake/unknown changes, working/done priority, tab removal, session replacement under the same tab ID, independent snapshot identities, missing inputs, and a folder workspace key.
  • ORCA_BACKGROUND_LAUNCH=1 pnpm --config.verifyDepsBeforeRun=false check:changed --maxWorkers=2: passed all 21 checks in 3170.6s on the published commit. All 34 focused tests and baseline-failing operation counts also passed.

Rerun the changed regressions with ORCA_BACKGROUND_LAUNCH=1 pnpm test src/renderer/src/components/terminal-pane/pane-title-update-global-scan-budget.test.tsx src/renderer/src/store/slices/structured-chat-slept-at.test.ts --maxWorkers=2.

Tests ran in the background with ORCA_BACKGROUND_LAUNCH=1. No native-focus or visible-window test was run.

AI Disclosure

Review

Reviewed immutable input ownership, cache invalidation, status priority, folder workspace inputs, and remote tab projection writers. The cache uses weak snapshot ownership and adds no runtime resource lifecycle.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Pure renderer selectors have no platform-specific code or protocol changes. Native macOS/Windows, live remote transport, forced-GC retention, and packaged Electron performance were not measured. The cold scan remains proportional to the changed workspace bucket; an actual global sleep-map change invalidates each observed bucket.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

The required local changed-file gate is recorded above; the full build is left to CI.

@OrcaWin
OrcaWin force-pushed the OrcaWin/perf-chat-presence-cache branch from dbb8fa0 to a4b1c33 Compare October 28, 2026 07:30
@OrcaWin
OrcaWin marked this pull request as ready for review October 28, 2026 07:30
@coderabbitai

coderabbitai Bot commented Oct 28, 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 9 minutes.

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: 7cdf3ca7-266c-4afe-af8c-d93f9af5a0b0
Commits

Reviewing files that changed from the base of the PR and between bd9455b and a4b1c33.

Files selected for processing: 3
  • src/renderer/src/components/terminal-pane/pane-title-update-global-scan-budget.test.tsx
  • src/renderer/src/store/slices/structured-chat-slept-at.test.ts
  • src/renderer/src/store/slices/structured-chat-slept-at.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 2d3e7e4 into main Oct 28, 2026
69 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