Skip to content

perf(renderer): gate the jump palette's status-map subscriptions while closed - #7558

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-jump-palette-status-gate
Jul 6, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-jump-palette-status-gate

Conversation

@nwparker

@nwparker nwparker commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Follow-up scan for more #7545-class wins — always-mounted renderer components that subscribe to hot store maps they only need under a narrow condition. Independently surfaced by two finders and adversarially verified (churn confirmed, always-mounted confirmed, gate sound); this was the highest-value survivor.

1. Description

WorktreeJumpPalette (Cmd+J) is always mounted — App.tsx renders <CommandDialog open={visible}>, and once opened it stays mounted for the rest of the session. It opened five whole-map Zustand subscriptions:

agentStatusByPaneKey, runtimePaneTitlesByTabId, ptyIdsByTabId,
terminalLayoutsByTabId, tabsByWorktree

Those five feed only the palette's row derivations — sortWorktreesSmart over every worktree, isInactiveWorkspace filtering, buildSearchableWorkspaceTabs, and the getWorktreeStatus dots — all consumed only inside the open dialog. But two of them, runtimePaneTitlesByTabId and agentStatusByPaneKey, get their top-level reference replaced on every terminal pane-title escape sequence and every agent-status transition — the two hottest maps in the app. So while the palette was closed (virtually always), every such write re-rendered the whole palette and recomputed its per-worktree status sort over the full worktree list.

Fix (same shape as #7545): collapse the five subscriptions into one useShallow selector (selectPaletteStatusInputs, extracted to worktree-jump-palette-status-inputs.ts) that returns a shared frozen constant while the palette isn't active. Idle palettes then stay referentially equal across the title/status churn and stop re-rendering; the live maps flow through the instant it opens (same render — visible derives from the same store snapshot, so there's no stale first frame).

Close-animation safety: visible flips false synchronously on close, but the CommandDialog content stays mounted while it fades/zooms out. A naive gate would flash the rows empty/reordered mid-animation, so a small statusInputsLingering latch keeps the maps live for 300ms past close (comfortably beyond the ~150–200ms animation), after which the gate drops the subscription.

2. Undeniable evidence + measurable improvement

  • Deterministic unit proof (worktree-jump-palette-status-inputs.test.ts, red→green — the honest, non-flaky evidence): the selector returns the same EMPTY_PALETTE_STATUS_INPUTS reference even after runtimePaneTitlesByTabId/agentStatusByPaneKey churn while inactive (→ useShallow skips the render); exposes the live maps the instant it becomes active; keeps them live during the close linger; and shallow-changes only when a subscribed map ref actually changes while active (so the open palette re-derives exactly as before).
  • Behavioral preservation: existing WorktreeJumpPalette tests pass unchanged; typecheck + oxlint + react-doctor clean.
  • Metric: renders-per-unrelated-title/status-write for the closed palette drops from 1 → 0, and it no longer recomputes a whole-worktree-list status sort on that churn.

3. ELI5

The Cmd+J switcher was quietly listening to every terminal in the app renaming its tab or flipping agent status — and redrawing its whole list each time — even while it was closed and invisible. Now it ignores all that chatter until you actually open it (and keeps listening just long enough to fade out cleanly).

4. Trade-offs that regress the end experience

None material. The five maps drive only the palette's own rows, which are shown only while it's open; the linger removes the one theoretical close-animation flash. migrationUnsupportedByPtyId (identity-preserving on the status path) and every non-status subscription are left exactly as they were.

Made with Orca 🐋

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a new module exporting PaletteStatusInputsState, a frozen EMPTY_PALETTE_STATUS_INPUTS singleton, and selectPaletteStatusInputs, which conditionally returns either the empty singleton or five live status map references from app state. A corresponding Vitest test file validates selector behavior for active/inactive states and reference stability. WorktreeJumpPalette is updated to import this selector along with useShallow, replacing several individual store selections with one shallow-gated selection. A new statusInputsLingering state and 300ms linger timeout keep status map subscriptions active during the palette's close animation.

Sequence Diagram(s)

Included in the hidden review stack artifact above.

Related PRs: None identified.

Suggested labels: refactor, renderer

Suggested reviewers: None identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description has a strong summary and testing notes, but it misses the required Screenshots and Security Audit sections and the cross-platform review confirmation. Add the template headings, include 'No visual change' or screenshots, expand Testing into the checklist, and add explicit macOS/Linux/Windows review and a Security Audit summary.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: gating the jump palette's status-map subscriptions while closed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (4)
src/renderer/src/components/worktree-jump-palette-status-inputs.ts (2)

14-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Trim the "why" comments to the guideline's one/two-line limit.

Both blocks (10 lines each) explain valuable context, but the repo guideline caps design-rationale comments at one or two lines.

✏️ Suggested trim
-// Why: shared frozen bundle returned whenever the Cmd+J jump palette isn't
-// active. The two hottest maps here — agentStatusByPaneKey and
-// runtimePaneTitlesByTabId — get a new top-level identity on every agent-status
-// transition and every terminal pane-title write app-wide. The palette is always
-// mounted (App.tsx renders <CommandDialog open={visible}>) and stays mounted for
-// the whole session once opened, so subscribing to them while it's closed
-// re-rendered the whole palette — and recomputed its per-worktree live/working-dot
-// sort over every worktree — on unrelated terminal chatter. A useShallow
-// subscription keeps this same reference across that churn, so the closed palette
-// stops reacting. Frozen so the shared singleton can't be mutated.
+// Why: shared, frozen no-op bundle used while the always-mounted palette is
+// closed, so useShallow stays referentially stable across unrelated status churn.

Based on coding guidelines, **/*.{ts,tsx,js,jsx} requires "Keep comments short — one or two lines, capturing only the non-obvious reason."

Also applies to: 32-41

Source: Coding guidelines


24-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Type the frozen singleton as Readonly<PaletteStatusInputs>.

Object.freeze gives runtime immutability, but the explicit PaletteStatusInputs annotation discards that guarantee at compile time — nothing stops a future edit like EMPTY_PALETTE_STATUS_INPUTS.tabsByWorktree = {...} from type-checking, even though it will silently no-op at runtime.

🛡️ Proposed fix
-export const EMPTY_PALETTE_STATUS_INPUTS: PaletteStatusInputs = Object.freeze({
+export const EMPTY_PALETTE_STATUS_INPUTS: Readonly<PaletteStatusInputs> = Object.freeze({
   agentStatusByPaneKey: {},
   runtimePaneTitlesByTabId: {},
   ptyIdsByTabId: {},
   terminalLayoutsByTabId: {},
   tabsByWorktree: {}
 })
src/renderer/src/components/WorktreeJumpPalette.tsx (2)

346-350: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Trim the "why" comments to one or two lines.

Both blocks (5 and 12 lines) restate rationale already captured in worktree-jump-palette-status-inputs.ts; consider linking to that module's doc comment instead of duplicating the full explanation here.
Based on coding guidelines, **/*.{ts,tsx,js,jsx} requires "Keep comments short — one or two lines, capturing only the non-obvious reason."

Also applies to: 363-374

Source: Coding guidelines


346-362: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add a fake-timers test for the close-linger gate. Cover the 300ms delay and the reopen-before-timeout path so statusInputsLingering doesn’t regress.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a98b16e5-0dd6-4755-906e-6fb3617d09e0

📥 Commits

Reviewing files that changed from the base of the PR and between b41cab1 and 774e46a.

📒 Files selected for processing (3)
  • src/renderer/src/components/WorktreeJumpPalette.tsx
  • src/renderer/src/components/worktree-jump-palette-status-inputs.test.ts
  • src/renderer/src/components/worktree-jump-palette-status-inputs.ts

@nwparker
nwparker merged commit 63384d0 into main Jul 6, 2026
2 checks passed
@nwparker
nwparker deleted the nwparker/perf-jump-palette-status-gate branch July 6, 2026 20:31
Jinwoo-H added a commit that referenced this pull request Jul 6, 2026
Brings in 9 commits: deferred remote catalogs at startup (#7087),
owner-aware pane title decision gating the Gemini GPU fallback (#7458),
incremental transcript parsing for JSONL agents (#7593), gh rate-limit and
git-status spawn-churn fixes (#7595), WSL Codex session bridging (#7477),
jump-palette subscription gating (#7558), and the IDE font dropdown fix.

Conflict resolutions (our structure, main's semantics):
- pty-connection.ts onTitleChange: kept this branch's third parameter and
  stale-derived-title guard (staleWorkingTitleClear must never feed
  completion tracking), grafted main's resolvePaneTitleDecision so the
  display label, GPU policy, and observeTitle all ride the owner-aware
  decision (#7428/#7447).
- App.tsx startup: kept this branch's publishTerminalViewAttributesAtAppStart
  (hidden-at-launch OSC 10/11 replies) ahead of main's restructured
  local-first startup; dropped this branch's early ui.get() overlap — main's
  #7087 now awaits ui.get at effectively the same point, making it redundant.

Gates: typecheck clean; 4298 tests across src/main/ipc, src/main/daemon,
terminal-pane, pane-manager. The delivery path (ipc/pty.ts, dispatcher,
scheduler, snapshots) had no conflicts and no incoming changes.

Co-authored-by: Orca <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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