Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

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

Problem

High-frequency streaming events (stream-delta, tool-call-delta, reasoning-delta) were triggering immediate state bumps and React re-renders on every token. This caused noticeable lag during fast streaming of markdown content.

Solution

Add a debounce mechanism (~16ms / 60fps cap) for delta event UI notifications:

  • Data integrity preserved: The aggregator is updated immediately on each event - no data is ever lost
  • UI updates batched: states.bump() calls are debounced so React only re-renders at most ~60 times per second
  • Stream boundaries handled: stream-end and stream-abort flush any pending debounced bumps to ensure final state is visible immediately
  • Cleanup on removal: Debounce timers are cleared when workspaces are removed to prevent stale callbacks
  • No change for other events: Tool call start/end, reasoning end, etc. still bump immediately since they're lower frequency

Risk Assessment

Risk Assessment
Data loss None - aggregator updated immediately
Timer leak Mitigated - cleaned up on workspace removal
Final state hidden None - flushed on stream-end/abort
Perceived delay None - 16ms is sub-perceptual

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 debounce-markdown-streaming branch from 0f4d86a to faa1aca Compare December 8, 2025 21:22
…reaming

High-frequency streaming events (stream-delta, tool-call-delta, reasoning-delta)
were triggering immediate state bumps and React re-renders on every token.
This caused noticeable lag during fast streaming.

Changes:
- Add debounce mechanism (~16ms / 60fps cap) for delta event UI notifications
- Data is still updated immediately in aggregator - only UI notification is debounced
- Stream-end and stream-abort flush pending debounces to ensure final state visibility
- No behavior change for other event types (tool-call-start/end, etc.)

_Generated with mux_
@ammar-agent ammar-agent force-pushed the debounce-markdown-streaming branch from faa1aca to 4ac921f Compare December 8, 2025 21:24
@ammario ammario merged commit 7139114 into main Dec 8, 2025
18 checks passed
@ammario ammario deleted the debounce-markdown-streaming branch December 8, 2025 21:31
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