Skip to content

[perf-remote] perf(renderer): gate unread badge scans - #13554

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-gate-unread-dock-badge
Aug 10, 2026
Merged

[perf-remote] perf(renderer): gate unread badge scans#13554
nwparker merged 1 commit into
mainfrom
nwparker/perf-gate-unread-dock-badge

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary

  • Stop the always-mounted unread badge hook from rescanning every workspace and terminal tab on unrelated Zustand publications.
  • Shallow-select the three badge inputs and recompute only when worktrees, terminal tabs, or unread markers actually change.
  • Preserve badge updates and clearing when any relevant input changes.

ELI5

Orca keeps an OS unread badge in sync. Before this change, every renderer state update asked, “How many unread workspaces do I have?” Answering could walk every workspace and every terminal tab—even when the update was only a remote host status or agent-status tick.

Remote Orca servers amplify both sides: they add workspaces/tabs to count and produce more unrelated renderer updates.

Now Orca reuses the count until one of the three things that can affect it actually changes. A remote session update that replaces terminal tabs still recounts; unrelated remote status and agent updates do not.

Synthetic benchmark

Median per unrelated store publication on Node 24. Each fixture has one terminal per worktree and one unread terminal in the final entry. This is a selector microbenchmark, not end-to-end frame timing.

Worktrees + tabs Previous recount Shallow gate Reduction
40 + 40 3.36 µs 0.315 µs ~10.7×
100 + 100 9.45 µs 0.298 µs ~31.7×
250 + 250 21.6 µs 0.297 µs ~72.7×
500 + 500 46.9 µs 0.307 µs ~153×

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Focused validation:

  • 7 tests across the badge hook and badge-count behavior
  • Hot-path regression uses 100 worktrees, 100 tabs, one unread tab, 100 agent-status publications, and a runtime-status replacement
  • Badge behavior asserts terminal unread transitions 0 → 1 → 0
  • pnpm run check:code-quality:changed — zero findings
  • pnpm run check:max-lines-ratchet
  • git diff --check origin/main...HEAD

AI Review Report

An adversarial test review found two low-severity gaps:

  • The first test kept the worktree itself unread, masking whether terminal unread state changed the external badge. The fixture now uses a read worktree and proves 0 → 1 → 0.
  • The initial wording could imply all remote agent activity avoids recounting, even when a mirrored session legitimately replaces terminal tabs. The code comment, test name, and PR claim now explicitly cover only unrelated publications.

A production mutation audit found the selected worktree, tab, and unread containers are replaced rather than mutated in place, so shallow reference gating is safe. No correctness, cleanup, mock-pollution, or cross-platform issue remained after the changes.

Cross-platform review found no changed shortcut, label, path, shell, native-module, or Electron platform branch. The existing badge API behavior remains identical on macOS, Linux, and Windows.

Security Audit

No new input handling, command execution, filesystem path handling, auth, secrets, dependency, IPC, RPC, or remote-wire behavior. This only gates an existing renderer-side computation over existing in-memory state. No follow-up security work identified.

Notes

  • No visual, IPC, RPC, or remote wire-format change.
  • Mixed client/server versions are unaffected.
  • Relevant mirrored tab changes still recompute immediately; only publications preserving all three badge inputs are skipped.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The unread dock badge hook now subscribes to worktree, tab, and unread-terminal-tab state with a shallow Zustand selector. It memoizes unread-count calculation before synchronizing the dock badge. Tests use the real app store, reset state between cases, and verify that unrelated updates and parent renders do not recount while relevant state changes do.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the renderer performance change that gates unread badge scans.
Description check ✅ Passed The description covers the summary, visual impact, testing, AI review, security audit, and platform notes with relevant validation details.
✨ 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.

@nwparker nwparker changed the title perf(renderer): gate unread badge scans [perf-remote] perf(renderer): gate unread badge scans Aug 10, 2026
@nwparker
nwparker merged commit d15a554 into main Aug 10, 2026
45 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