Skip to content

perf(renderer): anchor spinner phase from animationstart only - #13987

Merged
nwparker merged 1 commit into
mainfrom
nwparker/perf-agent-spinner-anchor
Aug 12, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/perf-agent-spinner-anchor

Conversation

@nwparker

@nwparker nwparker commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The working ring is phase-locked so every spinner ticks on the same compositor frame. That anchoring runs from two places today — a ref callback and an onAnimationStart handler — and both call el.getAnimations(). The ref call forces a synchronous style recalc at commit, per ring, to set a phase that animationstart sets one frame later anyway.

This drops the ref call and keeps animationstart as the sole anchor.

Measured

Real Chromium, 200 rings, median of 6 reps with warmup discarded:

ref + animationstart (main) animationstart only
Synchronous blocking work at mount 24 ms 0.1 ms
Total to settled 67.1 ms 62.8 ms

The work isn't eliminated so much as moved off the commit path: the deferred handler cost is comparable, but it runs between frames instead of blocking one. Total is a wash; the blocking chunk is what mattered.

Phase behaviour is identical to main in every case tested — 24 rings mounted one frame apart, counting distinct computed transforms (1 = locked):

main this PR
Cross-frame mount 1 1
After animation restart 1 1
After display:none reveal 1 1
Sampled per-frame during mount 1 1

Why not a negative animation-delay instead

A static delay computed once at mount is cheaper still (0.3 ms, no handler), and it was the original proposal. It is wrong: animation-delay is static, so a restart replays the stale mount-time offset and the rings fan out across steps. Measured on the same harness: 8 distinct phases after a restart, 3 after a display:none reveal, versus 1 for the JS anchor. Phase loss is a steady-state cost, which dominates a one-time mount saving.

Why not a shared JS clock

Benchmarked on a quiet machine at N = 1, 12, 40, 100, 200, 400. Style-recalc cost of a 12 Hz clock writing style.transform on N rings:

N 1 40 100 200 400
JS clock recalc 3.9 ms 11.6 ms 23.8 ms 44.4 ms 83.1 ms
CSS recalc 0.1 ms 0.3 ms 0.6 ms 1.3 ms 0.6 ms

The clock is the variant that pays per element. This matches the production root-cause in #12359 (41 spinners → ~490 style writes/s → 97% of DOM mutation traffic, keystroke p90 363 ms → 19 ms once stopped) and explains the earlier result in #9380 that pointed the other way: that comparison was against staggered CSS, before phase-locking existed.

Caveat on scope: TaskDuration in that harness is noise for the CSS variants (rep-to-rep spread exceeds the across-N range), so it can establish the JS clock's per-element cost but cannot rank locked vs staggered CSS. Reported as measured, not inferred.

Reduced motion

Under prefers-reduced-motion the rule resolves to animation: none, so there is no animation to start and none to anchor. On main both paths are already no-ops there — getAnimations() finds no match and animationstart never fires — so removing the ref call adds no exposure. Pinned by a test.

An attempt to verify this in a browser was inconclusive: --force-prefers-reduced-motion did not take (matchMedia(...).matches === false), so no browser-level result is claimed.

motion-reduce:border-t-yellow-500 from #9515 is untouched — the static ring must render complete, not as a frozen 3/4 arc.

Tests

6 in AgentWorkingSpinner.test.tsx (up from 4), 22 across the ring's consumers. New coverage: mount performs no getAnimations() call; every animation start re-anchors; unrelated animations on the same element are ignored; reduced motion anchors nothing. Verified the first two fail if the ref call is restored.

Made with Orca 🐋

The ref callback forced a synchronous style recalc per mount to set a
phase that animationstart sets one frame later anyway. Measured in
Chromium at 200 rings: 24ms of blocking work removed, phase identical
across cross-frame mount, restart, and display:none reveal.

Keeps the JS anchor rather than a negative animation-delay: a static
delay replays its stale mount-time offset on restart, fanning the rings
across steps (measured 8 distinct phases after restart, 3 after a
display:none reveal, vs 1 for the anchor).

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

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated AgentWorkingSpinner to synchronize its animation phase through onAnimationStart instead of ref assignment. The component anchors matching animations to the shared document epoch. Tests cover initial and repeated animation starts, mount behavior without animation queries, reduced-motion rendering, and ignored events for unrelated animations.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change, motivation, measurements, alternatives, reduced motion, and tests, but omits required issue, visual proof, review, and checklist sections. Add the required template sections, link an issue with “Fixes #…”, provide visual proof or N/A with a reason, and complete the review and checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states that spinner phase anchoring uses animationstart only, matching the main change.
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 (1)
src/renderer/src/components/AgentWorkingSpinner.tsx (1)

6-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Condense the rationale comments.

Keep one concise “why” comment where it adds context. Remove repeated implementation detail from the test comments.

  • src/renderer/src/components/AgentWorkingSpinner.tsx#L6-L9: reduce this rationale to one concise statement.
  • src/renderer/src/components/AgentWorkingSpinner.test.tsx#L53-L56: rely on the test name or use one short rationale statement.
  • src/renderer/src/components/AgentWorkingSpinner.test.tsx#L108-L110: rely on the test name or use one short rationale statement.

As per coding guidelines: “Comments must be concise, non-obvious, and brief—prefer one line.” Based on learnings: concise comments should explain non-obvious rationale (“WHY”), not obvious mechanics.

Sources: Coding guidelines, Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a28d0b7b-46d6-4411-a444-8d082526f6fc

📥 Commits

Reviewing files that changed from the base of the PR and between fd2afc1 and 36ccbef.

📒 Files selected for processing (2)
  • src/renderer/src/components/AgentWorkingSpinner.test.tsx
  • src/renderer/src/components/AgentWorkingSpinner.tsx

@nwparker
nwparker merged commit a90a18d into main Aug 12, 2026
45 checks passed
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