Files
openchamber/packages
Nguyễn Ngô ThượngandBohdan Triapitsyn 5ab9b1a96e perf(streaming): buffer SSE parts via rAF to coalesce re-renders (#487)
* perf(streaming): buffer SSE parts via rAF to coalesce re-renders

addStreamingPart previously called _addStreamingPartImmediate directly
for every SSE token (~50-100/sec during streaming), causing one Zustand
set() and potential re-render per token.

Now incoming parts are buffered in a module-level queue and flushed once
per animation frame. React 18's automatic batching coalesces the
synchronous set() calls within the rAF callback into a single paint.

Also handles edge cases:
- completeStreamingMessage flushes pending queue before completing
- abortCurrentOperation discards queued parts for the aborted session
- cancelAnimationFrame prevents stale flushes on abort/complete

* perf(streaming): add timeout-backed flush for rAF queue batching

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
2026-02-24 12:07:05 +02:00
..