perf: skip syntax highlighting while a message is streaming - #433
Open
k0n9-devx wants to merge 1 commit into
Open
perf: skip syntax highlighting while a message is streaming#433k0n9-devx wants to merge 1 commit into
k0n9-devx wants to merge 1 commit into
Conversation
k0n9-devx
force-pushed
the
perf/streaming-render
branch
from
August 8, 2026 15:17
133fbbd to
843dc6a
Compare
…odeBlock and toolResults map Streaming updates re-rendered the live message on every SSE message_update, re-tokenizing the whole growing code block with Prism each time. Render code fences as plain monospace text while the message is streaming and highlight once on completion. Also memoize CodeBlock (unchanged code must not re-run tokenization when the parent markdown re-renders) and hoist ChatWindow's toolResults Map into a useMemo keyed on messages so its identity stays stable across streaming updates.
k0n9-devx
force-pushed
the
perf/streaming-render
branch
from
August 8, 2026 15:17
843dc6a to
fabd15d
Compare
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.
Problem
While a message streams, every
message_updatere-renders the liveMessageView, andCodeBlockre-runs Prism over the entire growing code fence on each update. A long code block gets re-tokenized hundreds of times before it completes. On phones this is the largest single CPU cost of streamed rendering — enough to cause visible thermal throttling on remote access.Two smaller issues compound it:
CodeBlockisn't memoized, so any parent markdown re-render re-tokenizes unchanged code.ChatWindowrebuilds thetoolResultsmap inline on every render, giving it a new identity each time.Change
CodeBlockinmemo.toolResultsmap into auseMemokeyed onmessagesso its identity is stable across streaming updates.Testing
tsc --noEmitandeslintcleanlib/markdown.test.mjspass; added twoCodeBlocktests (plain output while streaming, tokenized output once complete)