Repository navigation
perf(renderer): stop agent spinners from keeping the frame pipeline awake (one shared clock, hidden-window stop) - #9380
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a shared clock that directly updates registered agent spinner elements, with visibility and reduced-motion handling. Introduces the reusable 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
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. Comment |
|
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):
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. |
|
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):
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 |
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]>
…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]>
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.transformdirectly and goes fully idle between ticks.Live interleaved A/B/A (dev app post-#9395, renderer process, one working agent, 20s windows):
~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):
spin 1s steps(12)(what we had)spin 3s steps(12)— 3× sloweranimation-play-state: pausedTwo lessons baked into code comments:
Design
agent-spinner-clock.ts(~130 lines, renderer-only): module-level element registry + onesetInterval. 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.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.visibilitychangestops 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
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.SystemInfo.getProcessInfo, 15–20s windows after settle.Tests
agent-spinner-clock.test.ts: phase-sync across late joiners, hidden-stop/visible-resume viavisibilitychange, timer + listener teardown on last unregister, reduced-motion.data-agent-spinnercontract (no CSS animation classes).Risk / rollback