Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

@ammar-agent ammar-agent commented Dec 8, 2025

Problem

The Shimmer component was using motion/react with backgroundPosition animation which runs on the main thread, causing significant frame drops during "Thinking" state when the UI is already under load from streaming.

Solution

1. GPU-accelerated shimmer via Web Worker

Replaced motion/react with a Web Worker + OffscreenCanvas approach:

  • Animation loop runs entirely off the main thread
  • Single worker manages all shimmer instances via Comlink
  • Main thread only handles initial setup and cleanup
  • Graceful fallback to main thread if worker fails

2. Adaptive streaming updates via requestIdleCallback

Replaced fixed 32ms debounce timer with requestIdleCallback:

  • Fast machines get more frequent UI updates
  • Slow machines naturally throttle without dropping data
  • 100ms timeout ensures updates happen even under sustained load
  • Adapts to actual CPU availability rather than hardcoded frame budget

Files Changed

  • src/browser/workers/shimmerWorker.ts - NEW: Web Worker for off-thread animation
  • src/browser/components/ai-elements/shimmer.tsx - Rewritten with canvas + worker
  • src/browser/stores/WorkspaceStore.ts - requestIdleCallback for delta coalescing

Generated with mux

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@ammar-agent ammar-agent force-pushed the fix-shimmer-frame-drops-thinking branch 12 times, most recently from 5e4d310 to d041654 Compare December 8, 2025 21:35
…orms

The Shimmer component was using motion/react with backgroundPosition animation
which runs on the main thread and causes significant frame drops during
'Thinking' state when the UI is already under load.

Changed to CSS transform animation which runs on the compositor thread:
- Removed motion/react dependency from shimmer component
- Use translateX transform instead of backgroundPosition
- Render text twice: base layer (dimmed) + sliding highlight layer
- Added text-shimmer keyframe animation to globals.css

This matches the approach already used for CompactionBackground shimmer.

_Generated with mux_
@ammar-agent ammar-agent force-pushed the fix-shimmer-frame-drops-thinking branch from d041654 to e961f7d Compare December 8, 2025 21:41
Replace fixed 32ms debounce timer with requestIdleCallback for delta
event coalescing. This adapts to actual CPU availability:
- Fast machines get more frequent UI updates
- Slow machines naturally throttle without dropping data
- 100ms timeout ensures updates happen even under sustained load

The idle callback approach is more robust across different hardware
since it uses the browser's native idle detection rather than a
hardcoded frame budget.
@ammar-agent ammar-agent changed the title 🤖 perf: fix shimmer animation frame drops during Thinking 🤖 perf: fix shimmer frame drops + adaptive streaming updates Dec 8, 2025
@ammar-agent ammar-agent changed the title 🤖 perf: fix shimmer frame drops + adaptive streaming updates 🤖 perf: fix shimmer frame drops + use requestIdleCallback for streaming Dec 8, 2025
@ammario ammario merged commit 01513de into main Dec 8, 2025
19 checks passed
@ammario ammario deleted the fix-shimmer-frame-drops-thinking branch December 8, 2025 21:51
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.

2 participants