Skip to content

perf(renderer): stop agent spinners from keeping the frame pipeline awake (one shared clock, hidden-window stop) - #9380

Merged
nwparker merged 2 commits into
mainfrom
nwparker/spin
Jul 20, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/spin

Conversation

@nwparker

@nwparker nwparker commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Rescoped after #9395 merged — originally this PR also carried a main→renderer window-visibility IPC relay to work around setBackgroundThrottling(false) pinning document.visibilityState on macOS. #9395 re-enabled throttling, which made visibilitychange work natively and the hidden-window burn stop on its own, so the relay (main/preload/api-types/web-stub changes) has been removed. This PR is now renderer-only and targets the case throttling can never help: the visible window.

TL;DR

The yellow "agent is working" spinners (sidebar worktree dots, nested per-agent rows in worktree cards, terminal tabs, dashboard, AI Vault subagents) each ran their own infinite CSS animation. An active CSS animation keeps Chromium's frame/compositor pipeline permanently awake and pays per element — for the entire duration of every agent run, on a surface users keep visible for hours.

This PR keeps the spinner looking the same (same ring, same 30° step grain) but rotates every mounted one from one shared 12-steps/s clock (frame-for-frame identical cadence to the old animation) that writes style.transform directly and goes fully idle between ticks.

Live interleaved A/B/A (dev app post-#9395, renderer process, one working agent, 20s windows):

Leg CPU
Shared clock 21.0 ms CPU/s
Old CSS animation (injected over same session) 37.0 ms CPU/s
Shared clock again 21.5 ms CPU/s

~16 ms CPU/s saved with a single spinner — and the clock is flat in spinner count (one timer, N elements) where the CSS scheme scales per element, so parallel-agent sidebars save proportionally more. An earlier same-methodology run measured 23.5 → 10.0 ms/s; both runs agree on the shape: roughly 40–60% of spinner-attributable renderer CPU, growing with agent count.

ELI5

Imagine a wall of clocks where every clock has its own battery motor running continuously. That was the old spinners: each one told the browser "keep the animation machinery running," and the browser woke up for every frame slot to service it.

The new version is one person walking past the wall six times a second, nudging every clock hand at once. Between nudges, everything sleeps. When the room empties (window hidden), the person stops — and with #9395 merged, the renderer now actually knows when the room is empty.

Why CSS animation is the wrong tool for an always-on spinner

Counter-intuitive benchmark results (headed Chromium, 8 spinners + realistic filler DOM):

Variant CPU
No animation ~6 ms/s
CSS spin 1s steps(12) (what we had) ~24 ms/s
CSS spin 3s steps(12) — 3× slower ~22 ms/s
CSS animation, animation-play-state: paused ~6 ms/s
JS clock 6Hz/30° (this PR) isolated ~28–34 ms/s, but live: 21 vs 37 ms/s
JS clock 12Hz (old look 1:1) ~39 ms/s — worse than CSS

Two lessons baked into code comments:

  1. Slowing a CSS animation barely helps — the cost is the always-armed animation machinery, not pixels. Only no active animation returns the pipeline to idle.
  2. Don't "smooth" by raising Hz — at 12Hz the JS clock costs more than the CSS animation it replaces. 6Hz with 30° steps keeps the old animation's step size (the grain that read as smooth) at half its wakeup rate.

Design

  • agent-spinner-clock.ts (~130 lines, renderer-only): module-level element registry + one setInterval. Register an element → it joins in phase with the shared dial (parallel agents tick in lockstep); unregister → last one out clears the timer and all global listeners. Zero cost when no agent is working.
  • Gates: document visibility (works natively again post-perf(window): re-enable macOS main-window background throttling #9395), prefers-reduced-motion (now respected by every spinner — the sidebar dot previously ignored it, and it live-reacts to OS setting changes), and the existing stale-visibility latch (stale-document-visibility.ts) so a wedged macOS occlusion tracker can't freeze spinners a user is provably looking at.
  • AgentWorkingSpinner.tsx: the shared ring, attached via a React 19 cleanup-ref. Both spinner primitives (StatusIndicator, AgentStateDot) render it, which covers every working-state spinner in the app by construction — sidebar dots, nested worktree-card agent rows, terminal tabs, dashboard rows, AI Vault subagents. rg 'animation:spin|animate-spin' over agent-status paths: clean.
  • Hidden-window interaction with perf(window): re-enable macOS main-window background throttling #9395: visibilitychange stops the clock outright (measured 0.7 ms/s hidden). Chromium's 1s hidden-timer clamp is irrelevant since the timer is cleared, not clamped.

Verification

  • Live (dev app on rebased branch, CDP-driven): spinner steps 0°→30°→…→330° at 6Hz; hide app → visibilityState: 'hidden', transform frozen, 0.7 ms CPU/s; show → immediate resume (clock ticks once on reconcile so the ring never looks stuck). A/B/A table above from the same session via injected <style> override.
  • Benchmarks: Playwright headed Chromium, CPU summed over all Chromium processes via CDP SystemInfo.getProcessInfo, 15–20s windows after settle.

Tests

  • agent-spinner-clock.test.ts: phase-sync across late joiners, hidden-stop/visible-resume via visibilitychange, timer + listener teardown on last unregister, reduced-motion.
  • Markup tests updated to the data-agent-spinner contract (no CSS animation classes).
  • Full renderer component suite, web typecheck, oxlint, oxfmt: green.

Risk / rollback

  • Purely visual + renderer-local; no main/preload/IPC changes. Cadence: 12 steps/s → 6 steps/s with identical 30° step size (full revolution 1s → 2s).
  • Failure modes are cosmetic (spinner frozen/stopped); agent status data flow untouched. SSH/web unaffected (web clients have real document visibility).

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a shared clock that directly updates registered agent spinner elements, with visibility and reduced-motion handling. Introduces the reusable AgentWorkingSpinner component and replaces inline working indicators in AgentStateDot and StatusIndicator. Updates renderer tests to validate the shared spinner marker and the absence of CSS animation classes.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it omits the required Screenshots, AI Review Report, and Security Audit sections from the template. Add the missing template sections, including screenshots or No visual change, a cross-platform AI review summary, and a basic security audit.
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the renderer spinner performance change and the shared-clock hidden-window stop.
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.

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

Copy link
Copy Markdown
Contributor Author

Cadence update after review feedback: 3Hz/45° read too step-like. Now 6Hz with 30° steps — the same step size as the old CSS animation (that grain is what read as smooth), at half its tick rate.

Benchmarked the whole cadence ladder before picking (isolated Chromium, 8 spinners + filler page):

Variant CPU
old CSS steps(12)/1s 23.6 ms/s
js 6Hz/30° (new) 33.9 ms/s isolated · 10.0 ms/s live A/B (vs 23.5 old, same session)
js 8Hz/30° 28.3 ms/s
js 10Hz/30° 30.3 ms/s
js 12Hz/30° (old look 1:1) 39.1 ms/s — worse than the CSS animation

Two takeaways baked into the code comment: (1) the isolated numbers overstate JS-clock cost vs the live app (timer wakeup floor dominates the synthetic page; in the real renderer the live A/B is 10.0 vs 23.5 ms/s, and the clock is flat in spinner count while CSS scales per element); (2) do not smooth further by raising Hz — at 12Hz the JS clock costs more than the CSS animation it replaced. The hidden-window stop (0.5 ms/s) is cadence-independent and unchanged.

Verified live: spinner steps 0°→30°→60°… at 6Hz in the dev app.

@nwparker

Copy link
Copy Markdown
Contributor Author

Cadence finalized at 12 steps/s (30°/step) — exact visual parity with the old animation. 6Hz was judged noticeably less smooth in a side-by-side comparison window, so the "save CPU by ticking slower" angle is dropped entirely; the clock now matches the retired CSS animation frame-for-frame.

Re-measured at full parity, live dev app, interleaved A/B/A/B (one working agent, 20s legs, renderer+GPU CPU):

Leg Renderer GPU Total
clock 12Hz 33.0 28.0 61.0 ms/s
old CSS 57.5 28.5 86.0 ms/s
clock 12Hz 33.5 27.5 61.0 ms/s
old CSS 47.0 29.0 76.0 ms/s

Bottom line: identical look, ~20 ms CPU/s saved (~2% of a core, ~25% of spinner-path cost) with one spinner — clock legs dead-stable at 61.0/61.0 while CSS legs wander 76–86. GPU cost is cadence-bound and identical (~28 ms/s both ways); the entire win is renderer-side per-element animation machinery, which also means it scales with agent count: N CSS animations each pay, the clock pays once.

Also sanity-checked the claim in a minimal Electron window (8 rings, nothing else): both modes measure ~2 ms/s — i.e. the CSS animation tax only materializes in a renderer with a real DOM/compositor load like Orca's. Which is exactly why the earlier isolated benchmarks undersold the clock and the live app numbers are the ones to trust.

Hidden-window behavior unchanged (clock stops via native visibilitychange post-#9395; measured 0.7 ms/s). Full renderer suite green at the new cadence (1168 files / 9420 tests).

Per-element infinite CSS spin animations kept Chromium's frame pipeline
awake for the whole agent run — measured live (interleaved A/B/A/B,
renderer+GPU): 86.0/76.0 ms CPU/s with the CSS animation vs 61.0/61.0
with the clock, one working agent, and the CSS cost scales per element
while the clock is one flat timer for N spinners.

The clock ticks 12 steps/s at 30° — frame-for-frame identical to the
retired animation — writes style.transform on registered elements, and
stops on document hidden (native visibilitychange post-#9395), under
prefers-reduced-motion (static ring keeps the filled top border from
#9515), and when the last spinner unmounts. The stale-visibility latch
keeps it spinning when proven user input contradicts the occlusion
tracker.

Co-authored-by: Orca <[email protected]>
…Sections

Pre-existing failure on main: i18n-jsx-spacing-guard requires {' '} after
the 'Filter' translate fallback, but the file had a bare JSX space (which
oxfmt collapses). Wrap the subject in a span so the explicit {' '} survives
formatting, matching the pattern in the other guarded files.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker merged commit 4d25de3 into main Jul 20, 2026
1 check passed
@nwparker
nwparker deleted the nwparker/spin branch July 20, 2026 05:53
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…wake (one shared clock, hidden-window stop) (stablyai#9380)

* perf(renderer): drive agent working-spinners from one shared clock

Per-element infinite CSS spin animations kept Chromium's frame pipeline
awake for the whole agent run — measured live (interleaved A/B/A/B,
renderer+GPU): 86.0/76.0 ms CPU/s with the CSS animation vs 61.0/61.0
with the clock, one working agent, and the CSS cost scales per element
while the clock is one flat timer for N spinners.

The clock ticks 12 steps/s at 30° — frame-for-frame identical to the
retired animation — writes style.transform on registered elements, and
stops on document hidden (native visibilitychange post-stablyai#9395), under
prefers-reduced-motion (static ring keeps the filled top border from
stablyai#9515), and when the last spinner unmounts. The stale-visibility latch
keeps it spinning when proven user input contradicts the occlusion
tracker.

Co-authored-by: Orca <[email protected]>

* fix(github): restore explicit space after Filter fallback in PRFilterSections

Pre-existing failure on main: i18n-jsx-spacing-guard requires {' '} after
the 'Filter' translate fallback, but the file had a bare JSX space (which
oxfmt collapses). Wrap the subject in a span so the explicit {' '} survives
formatting, matching the pattern in the other guarded files.

Co-authored-by: Orca <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
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