Repository navigation
Keep a streaming reply as plain text until it is final (1.2.2) - #8
Merged
Merged
Conversation
Text selection makes every paragraph of a message an AppKit-backed view that SwiftUI re-creates and hit-tests (hover tracking) on each update. For a long reply streamed 30 times a second that saturated the main thread: the window froze for seconds while the engine finished the reply into the stream buffer, then everything appeared at once. Sampled on an M2 Pro: 100% of the main thread in the SwiftUI graph update, a third of it in NSHostingView.didRequestHoverUpdate, the engine idle. The streaming message (and the thinking block while in progress) is plain SwiftUI text and becomes selectable when final; the UI flushes at 20 updates a second. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
🚀 Deploying Preview to Cloudflare 🚀Preview Deployments by commit
|
…stack Sampled on an M2 Pro with the 1.2.1 app, the main thread was saturated during a long reply (SwiftUI/AppKit layout, hover hit-testing, redraw) while the engine had long finished; afterwards the transcript could go blank. Changes, each measured with `sample` during a 1,000-word reply: - the reply streams into live state read only by the in-progress row; the conversation store is written once at the end (every token had re-rendered the sidebar, the inspector's AppKit sliders and the chat) - finished paragraphs keep their view; only the one being written re-renders; no hover tracking on rows while streaming - live-stats dot, "Thinking…" and typing dots are stepped, not repeat-forever animations (those rendered every frame with a full AppKit layout and hit-test pass each) - updates are paced by their measured main-thread cost (<= 20/s, never more often than twice the previous update's cost): main thread 52-60% idle during decode, from 0% - plain VStack for the message list (a LazyVStack could be left scrolled past stale content when the final layout replaced the streaming one) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Summary
Fixes the chat window freezing in the middle of a long reply — with any model — then showing the rest in one burst, and the transcript going blank when the reply finished.
Diagnosis (the running app sampled during the freeze on an M2 Pro): the main thread was 100% busy in SwiftUI/AppKit layout, hover hit-testing and redraw while the inference queue was idle — the engine (6–7 ms per token through
mlxr serve, no pauses) had already finished the reply into the stream buffer. Five causes, all in the chat view, each confirmed by re-sampling after the change:conversations, re-rendering the sidebar, the inspector (AppKit sliders) and the whole chat → the reply streams into live state that only the in-progress row reads; written to the conversation once at the end.Result: main thread 52–60% idle during decode of a long reply (was 0%). The blank transcript: a
LazyVStackcould be left scrolled past stale content when the final layout replaced the streaming one → plainVStack.Test plan
swift test(engine suite; changes are view code)sampleduring 1,000-word replies; final numbers above🤖 Generated with Claude Code