From 4fca9bfe16f89eff350b5ccc6985c98e87c7f09d Mon Sep 17 00:00:00 2001 From: Pascal Date: Mon, 2 Feb 2026 12:00:19 +0100 Subject: [PATCH] webui: add early exit for unchanged content in markdown processing Skip redundant processing when coalesced chunks result in identical content. During rapid streaming, multiple chunks may arrive and coalesce into pendingMarkdown while processing is ongoing. When the final coalesced content equals what was just processed, we can skip entirely. Also clarify the RAF yield comment: the key insight is that chunks arriving during the yield naturally coalesce, so we always render the latest state without explicitly tracking what to skip. --- .../lib/components/app/content/MarkdownContent.svelte | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/server/webui/src/lib/components/app/content/MarkdownContent.svelte b/tools/server/webui/src/lib/components/app/content/MarkdownContent.svelte index ee3e957283..7eabe43fcb 100644 --- a/tools/server/webui/src/lib/components/app/content/MarkdownContent.svelte +++ b/tools/server/webui/src/lib/components/app/content/MarkdownContent.svelte @@ -316,6 +316,11 @@ * @param markdown - The raw markdown string to process */ async function processMarkdown(markdown: string) { + // Early exit if content unchanged (can happen with rapid coalescing) + if (markdown === previousContent) { + return; + } + if (!markdown) { renderedBlocks = []; unstableBlockHtml = ''; @@ -513,8 +518,8 @@ await processMarkdown(nextMarkdown); - // Yield to browser for paint before processing next batch - // This prevents UI freeze at high token rates (250+ tok/s) + // Yield to browser for paint. During this, new chunks coalesce + // into pendingMarkdown, so we always render the latest state. if (pendingMarkdown !== null) { await new Promise((resolve) => requestAnimationFrame(resolve)); }