Coalesce streamed chat updates to keep the UI responsive - #48
Merged
Conversation
Applying every streamed token to the published message on the main actor saturates the run loop, so the transcript, thinking bubble, and "Working" animation stop repainting until an input event (#11). Buffer content, reasoning, and metrics deltas and flush them at ~30 Hz — with a trailing flush and a final flush on completion/cancel — so decode no longer starves the main thread.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When each streamed token is applied to the messages component on the main actor, the constant updates saturate the run loop, so live UI like the transcript, the thinking bubble, and the "Working" animation stops repainting until some input event nudges it (issue #11). Buffering the content, reasoning, and metric deltas and flushing them to the view at ~30 Hz moves those writes off the per-token path, so the main thread is no longer starved during generation. A trailing flush guarantees the last partial chunk still lands, and a final flush on completion or cancellation applies whatever remains in the buffer. The result is a transcript and thinking bubble that update smoothly the whole way through a response instead of freezing mid generation.