Repository navigation
perf(renderer): anchor spinner phase from animationstart only - #13987
Conversation
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]>
📝 WalkthroughWalkthroughUpdated 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/AgentWorkingSpinner.tsx (1)
6-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense 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
📒 Files selected for processing (2)
src/renderer/src/components/AgentWorkingSpinner.test.tsxsrc/renderer/src/components/AgentWorkingSpinner.tsx
…ai#13987) Co-authored-by: Orca <[email protected]>
Summary
The working ring is phase-locked so every spinner ticks on the same compositor frame. That anchoring runs from two places today — a
refcallback and anonAnimationStarthandler — and both callel.getAnimations(). The ref call forces a synchronous style recalc at commit, per ring, to set a phase thatanimationstartsets one frame later anyway.This drops the ref call and keeps
animationstartas the sole anchor.Measured
Real Chromium, 200 rings, median of 6 reps with warmup discarded:
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):
display:nonerevealWhy not a negative
animation-delayinsteadA static delay computed once at mount is cheaper still (0.3 ms, no handler), and it was the original proposal. It is wrong:
animation-delayis 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 adisplay:nonereveal, 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.transformon N rings: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:
TaskDurationin 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-motionthe rule resolves toanimation: 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 andanimationstartnever 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-motiondid not take (matchMedia(...).matches === false), so no browser-level result is claimed.motion-reduce:border-t-yellow-500from #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 nogetAnimations()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 🐋