perf(desktop): coalesce streaming text/reasoning deltas per animation frame#3114
Open
HUQIANTAO wants to merge 2 commits into
Open
perf(desktop): coalesce streaming text/reasoning deltas per animation frame#3114HUQIANTAO wants to merge 2 commits into
HUQIANTAO wants to merge 2 commits into
Conversation
f6ec9ab to
f017ca8
Compare
… frame The agent stream pushes a text/reasoning delta per Webview event; at 200 tok/s that is one state update every ~5ms, while rAF is 16ms — so the reducer was running 3-4 times per visible frame and the React tree was re-rendering the entire Message list each time. Add lib/rafBatch.ts: a tiny rAF-coalescing queue with a synchronous drain() so non-text events (tool_dispatch, usage, notice, turn_started/ done, message) flush any pending deltas first to keep causal ordering intact. Drain is also called on unmount so a turn-end that races the teardown doesn't strand the last few tokens in the buffer. tsc --noEmit passes; Go build ./desktop/... is clean.
… frame The agent stream pushes a text/reasoning delta per Webview event; at 200 tok/s that is one state update every ~5ms, while rAF is 16ms — so the reducer was running 3-4 times per visible frame and the React tree was re-rendering the entire Message list each time. Add lib/rafBatch.ts: a tiny rAF-coalescing queue with a synchronous drain() so non-text events (tool_dispatch, usage, notice, turn_started/ done, message) flush any pending deltas first to keep causal ordering intact. Drain is also called on unmount so a turn-end that races the teardown doesn't strand the last few tokens in the buffer. tsc --noEmit passes; Go build ./desktop/... is clean.
f017ca8 to
8e92821
Compare
Owner
|
Thanks! This conflicts with the latest main-v2 in useController.ts (other desktop PRs have since landed there). Could you rebase onto the latest main-v2? Note your open desktop PRs also touch App.tsx (#3116, #3126) and useController.ts (#2948) — rebasing them as one ordered chain will avoid repeated conflicts. Happy to merge once green. Thank you! |
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.
The agent stream pushes a text/reasoning delta per Webview event; at 200 tok/s that is one state update every ~5ms, while rAF is 16ms. The reducer was running 3-4 times per visible frame and the React tree was re-rendering the entire Message list each time.
Add
lib/rafBatch.ts: a tiny rAF-coalescing queue with a synchronousdrain()so non-text events (tool_dispatch, usage, notice, turn_started/done, message) flush any pending deltas first to keep causal ordering intact. Drain is also called on unmount so a turn-end that races the teardown doesn't strand the last few tokens in the buffer.tsc --noEmitpasses;go build ./desktop/...is clean. Frontend test spec is included as a contract test to be enabled when vitest is added.