Skip to content

perf(renderer): avoid per-second spinner animation events - #19407

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/spinner-perf
Sep 8, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/spinner-perf

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 15 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1155 $\color{#cf222e}{\Huge{\mathbf{−}}}$​222 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​933
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​245 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​231

ELI5

A spinner already turns without JavaScript driving every frame. But it still tells React "I finished a lap" every second, and those notifications interrupt the thread that handles typing.

This makes one animation contain a day's worth of laps. It looks and moves the same, but sends that notification once a day. Visible drawing still costs something; this removes avoidable bookkeeping.

What Changed

  • Change only the production CSS animation: 86,400 turns over 86,400 seconds, with 1,036,800 steps. That preserves one revolution and 12 steps per second.
  • Add repeatable hidden-Electron benchmarks for 1 and 200 real Git workspaces, including working root-agent and subagent rows, normal virtualization, expanded lineage, and real PTY typing under status traffic.
  • Reuse the existing scale fixture and extract the existing paced terminal-typing probe. Add pixel, phase, reduced-motion, and reveal checks.

Why

This preserves the two later historical fixes:

  • #9380 used a shared JavaScript clock to reduce frame-pipeline CPU. Its per-spinner style writes later caused typing stalls at scale.
  • #12359 moved rotation back to compositor CSS. The historical production report measured about 490 style writes/sec with 41 rings and input p90 of 363 ms versus 19 ms with the writes stopped.
  • #13987 moved phase synchronization to animationstart, avoiding a synchronous style query at every mount.

The new change removes almost all CSS iteration boundaries. React delegates animation-iteration listeners even without a component handler. It adds no DOM nodes, JS clocks, observers, or per-frame style writes, and keeps the existing phase synchronization. Historical benchmark totals are not directly comparable with this run.

Benchmarks

Scenario Renderer + GPU CPU ms/s, old → new Main-thread ms/s, old → new Echo p90 ms, old → new
one-agent 37.0 → 38.2 5.4 → 3.5 19 → 18–19
one-family 46.2 → 44.6 7.8 → 4.4 17–19 → 18–19
200-flat 141.6 → 122.8 28.2 → 16.3 26–28 → 26–28
200-lineage 324.6 → 295.6 140.8 → 70.0 159–239 → 93–160

"CPU ms/sec" is processor time spent during one second: 100 ms/sec is about 10% of one CPU core. Renderer + GPU-process CPU includes their other Orca work; it is not GPU hardware usage or total system CPU. Main-thread time is included in renderer time. Echo p90 means 90% of sampled keys were observed within that time.

Main-thread median time fell about 35–50% across all four cases, and separate 2.2-second native traces counted 6 / 16 / 324 / 2,802 iteration events before versus zero after. This verifies avoided work in the real app without installing a benchmark iteration listener.

Total CPU was roughly unchanged for one worktree, and fell 13% / 9% in the final 200-worktree runs. A shorter ablation had mixed total-CPU results (flat list: 89 → 108 CPU ms/sec) while still reducing main-thread time. The reliable claim is reduced event and main-thread work; the CPU percentages are local measurements, not guarantees. Typing stayed similar in small/flat cases and improved in the final lineage run; a shorter run showed similar lineage typing, so no general typing speedup is claimed.

The 200-workspace cases seed 400 working root agents and 800 subagents. Normal virtualization mounts 23 workspaces / 162 rings; expanded lineage mounts all 200 / 1,401 rings. Both have 15 visible rings. The one-workspace cases have 1 agent / 3 rings and 2 root agents + 4 subagents / 8 rings.

Four interleaved 10-second CPU samples per variant; two 64-key typing runs at 113 ms cadence, with up to 40 status updates/sec. CPU, typing, and native traces are measured separately. No samples are discarded. The detailed report includes every CPU sample and reproduction commands: full report.

These are macOS / Apple M4 measurements in hidden, unthrottled Electron 43.4.1 renderers. Worktrees and the typing PTY are real; working agent statuses are deterministic fixture data, not hundreds of live model sessions or streaming PTYs. Linux, Windows, SSH transport, native display latency, and battery use were not benchmarked.

A containment prototype saved more CPU but shifted a small ring by one pixel at minimum zoom on a 1× display; a pseudo-element prototype also hurt typing latency. Both are excluded. Their results are not the numbers for this patch. The optional benchmark variant retains containment for reproducible comparison.

Linked Issue

Related historical issue: STA-3328, addressed by #12359. This is follow-up performance work requested by the maintainer.

Visual Proof

N/A — no intended visual or interaction change. Automated CDP comparisons passed for 6/8 px rings at 1× and 2× display density, light/dark themes, supported zoom extremes, every phase, long elapsed times, and the daily wrap: 1,440 ring comparisons, allowing one antialias channel level of rounding.

Testing

  • 47 focused component tests.
  • Renderer typecheck (pnpm tc:web).
  • Fresh E2E build and both display-density rendering/behavior checks.
  • Four full-app performance scenarios and changed-code quality gate (including type-aware checks and React Doctor).
  • Automated tests added/updated.

The wider E2E TypeScript project has existing errors in unrelated specs; none were reported in the changed spinner benchmark or extracted typing files. Full-repository lint and tests were not run. All launched apps remained hidden and unfocused with ORCA_BACKGROUND_LAUNCH=1; no native-focus tests were run on the desktop.

Review

  • Production change is small and focused; supporting code makes the performance claim reproducible.
  • ELI5, historical comparison, raw measurements, and limitations documented.
  • Visual equivalence checked; rejected prototypes excluded.
  • Cross-platform, SSH/remote, and folder-workspace impact considered. No execution or wire-format changes.
  • Agent skill upstream boundary is not applicable; no upstream skill implementation is copied.

@pullfrog pullfrog 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.

ℹ️ One minor suggestion inline — this is a clean, well-validated change.

Reviewed changes

  • CSS-only core change — the working-spinner rotation moves from a per-second to a once-per-day iteration (86400s / steps(1036800, end) / rotate(86400turn)), keeping the identical 12 steps/second compositor-driven cadence while eliminating per-second animationiteration dispatch through React's synthetic event system.
  • Benchmark + equivalence suite — a new opt-in bench:spinners harness (isolated Electron harness plus full-app Playwright scenarios over 1/200 real Git workspaces with subagents and a real PTY typing probe), plus pixel/phase/reduced-motion/reveal checks including the daily-wrap boundary.
  • Probe extraction — measurePacedTyping factored out of the multi-workspace typing spec into tests/e2e/paced-terminal-typing.ts and parameterized by keyCount/keyCadenceMs.

The production change is confined to main.css. The steps() count is a timing-function parameter (no million-entry keyframe list, no JS clock), reduced-motion is unaffected, and the pixel-equivalence evidence — all 12 phases, the daily wrap, 1-channel antialias tolerance at 1× and 2× — is convincing that the larger rotate(86400turn) angle introduces no visual drift.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

Comment thread package.json Resolved
@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 5f88891c-eb3b-44ef-b122-5ebd22222e18

📥 Commits

Reviewing files that changed from the base of the PR and between 17164c4 and 724c520.

📒 Files selected for processing (1)
  • docs/reference/spinner-rendering-performance.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/reference/spinner-rendering-performance.md

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change updates working-spinner CSS animation timing to run for one day while preserving 12 steps per second. It adds documentation and component test coverage for the new timing and animation behavior. It introduces shared paced terminal typing measurements. It adds standalone spinner rendering and full-application benchmarks that seed workspaces and subagents, measure CPU and typing latency, verify pixels and reduced-motion behavior, trace iteration events, and write reports.

Merge Risk: 🔵 Low · up to 724c5

The spinner timing change is validated, but a failed terminal-typing benchmark can retain test resources until teardown. This is a bounded test-harness cleanup risk and does not indicate a production spinner behavior failure.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The directly linked issue [#9380] requires replacing independent CSS animations with a shared JavaScript clock and stopping that clock when the window is hidden. This PR intentionally retains composit… Link a follow-up issue whose objectives cover the long-duration CSS animation and benchmark work, or change the implementation to satisfy [#9380] by using the required shared JavaScript clock and hidden-window stop behavior.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 14 files. (1 skipped: … 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 identifies the primary change: reducing per-second renderer spinner animation events.
Description check ✅ Passed The description is detailed and covers the main template sections, including the change, rationale, testing, visual proof, limitations, and scope. It omits the explicit Notes and Checklist sections an…
Out of Scope Changes check ✅ Passed The production CSS change, spinner tests, benchmark fixtures, typing measurements, verification helpers, documentation, and Electron launch adjustment all support spinner performance measurement or va…
Full details: Linked Issues check

Explanation

The directly linked issue [#9380] requires replacing independent CSS animations with a shared JavaScript clock and stopping that clock when the window is hidden. This PR intentionally retains compositor CSS animation and changes its duration to reduce animation-iteration events, so it does not satisfy the linked issue’s primary implementation objective.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 14 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 519b979b-bfe3-4610-b1d0-599b67cbbec3

📥 Commits

Reviewing files that changed from the base of the PR and between 5882400 and e9ece25.

📒 Files selected for processing (20)
  • config/scripts/idle-cpu-renderer-scale-fixture.mjs
  • docs/reference/renderer-agent-status-performance.md
  • docs/reference/spinner-rendering-performance.md
  • package.json
  • src/renderer/src/assets/main.css
  • src/renderer/src/components/AgentWorkingSpinner.test.tsx
  • tests/e2e/paced-terminal-typing.ts
  • tests/e2e/spinner-workspace-fixture.ts
  • tests/e2e/spinner-workspace-perf.spec.ts
  • tests/e2e/terminal-multi-workspace-typing-latency.spec.ts
  • tests/tools/benchmarks/spinner-rendering/app-variants.mjs
  • tests/tools/benchmarks/spinner-rendering/fixture.css
  • tests/tools/benchmarks/spinner-rendering/fixture.tsx
  • tests/tools/benchmarks/spinner-rendering/index.html
  • tests/tools/benchmarks/spinner-rendering/main.ts
  • tests/tools/benchmarks/spinner-rendering/run.mjs
  • tests/tools/benchmarks/spinner-rendering/sample-cpu.mjs
  • tests/tools/benchmarks/spinner-rendering/trace-iterations.mjs
  • tests/tools/benchmarks/spinner-rendering/verify-pixels.mjs
  • tests/tools/benchmarks/spinner-rendering/verify-rendering.mjs

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment on lines +176 to +177
const maxTimerDriftMs = await timerDrift.evaluate((watcher) => watcher.stop())
await timerDrift.dispose()

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Stop timerDrift on every exit path.

If page.keyboard.type, the echo watcher, or a wait fails, control exits after Line 175 and skips this cleanup. The renderer interval and remote handle then remain active until page teardown. Put the stop() and dispose() calls in a finally that surrounds the measurement flow.

The script launches Electron via Playwright but skipped ensure:electron-runtime,
which every other Electron-launching bench script runs first.
@OrcaWin

OrcaWin commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed. Approving — the production change is a two-line CSS swap, the supporting benchmark code is opt-in and well isolated, and the write-up is unusually honest (it reports the ablation that contradicted its own CPU headline rather than dropping it).

Verified locally on this branch:

  • pnpm test AgentWorkingSpinner.test.tsx (6 passed), pnpm tc:web, changed-code quality gate (0 findings across 14 files).
  • pnpm bench:spinners --verify-only --scale-factor=1 reproduces as documented: 720 pixel comparisons, {"baseline":4,"candidate":0} iteration events.

One gap in the visual validation, non-blocking. verify-pixels.mjs pauses every animation before setting currentTime, so the "long elapsed times / daily wrap" comparisons all exercise the main-thread style path, not the compositor path that actually renders a running spinner. I re-ran the comparison against running animations (baseline and candidate rings anchored to the same startTime and compared within a single screenshot frame, so no wall-clock skew):

  • 0h / 1h / 18h / ~24h / 48h / 7d elapsed: 0 channel difference.
  • 6h and 12h elapsed: intermittent differences up to 24/255, on 111 of 484 pixels, mean 1.52 — i.e. above the 1-level tolerance the doc claims.

It is not a defect. Computed transform is identical on both sides (330.000 vs 330.000), phase and shape match, and a 24-frame capture inside one step shows zero frame-to-frame change on either ring, so there is no jitter or shimmer — just a fraction-of-a-pixel antialiasing difference on the ring edge at large accumulated angles. Magnified 20x the two rings are indistinguishable in shape and position.

Worth knowing because "Pixel tolerance is one channel level" in spinner-rendering-performance.md is stated more broadly than what was measured. If the checks get extended later, running-animation comparison at multi-hour ages is the case to add.

Also pushed one fix from @pullfrog's review: bench:spinners launched Electron without ensure:electron-runtime, unlike every other Electron-launching bench:* script, so it would fail at electron.launch() on a fresh checkout.

Left unaddressed: CodeRabbit's timerDrift cleanup note on paced-terminal-typing.ts:177 is pre-existing behavior carried over verbatim by the extraction, and the leaked interval only outlives a already-failing test by the length of page teardown.

@pullfrog

pullfrog Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Addressed the one actionable item in the approval note: the spinner-rendering-performance.md pixel-tolerance claim was scoped to what was actually measured. The doc now states that the comparison pauses each animation and sets currentTime (deterministic style path), that the one-channel tolerance applies to that path only, and that a running animation at multi-hour ages can differ by a few channels on the ring edge (antialias rounding, not phase/shape).

Pushed 724c520 to OrcaWin/spinner-perf. The timerDrift note and the non-blocking visual-validation gap were left as-is per the note's own framing (pre-existing / non-blocking).

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog 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.

✅ No new issues found — the prior feedback is addressed cleanly.

Reviewed changes

  • bench:spinners runtime gate — the bench:spinners script now runs pnpm run ensure:electron-runtime && node tests/tools/benchmarks/spinner-rendering/run.mjs, matching bench:idle-cpu / bench:startup / bench:daemon-coldstart so the Electron binary exists before electron.launch(). This resolves the sole thread from the prior review.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@OrcaWin
OrcaWin merged commit aeddfa4 into main Sep 8, 2026
3 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