You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤖 perf: debounce stream delta events to reduce markdown streaming lag (#988)
## 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`_
0 commit comments