fix(staged): memoize groupByVerb to prevent UI freeze on large sessions - #618
Merged
Conversation
groupByVerb() was called directly in the Svelte template expression, causing it to re-run on every render. For sessions with hundreds of tool calls, this meant hundreds of JSON.parse + string replace operations on every reactivity update, freezing the main thread. Pre-compute verb groups for all tool groups in a $derived block, caching both past-tense and present-tense variants. The template now does a cheap boolean lookup instead of re-running the expensive computation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
matt2e
force-pushed
the
fix/memoize-verb-group-computation
branch
from
April 14, 2026 05:07
843ffd2 to
2773f38
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.
Summary
groupByVerb()results for all tool groups in a$derivedblock, caching both past-tense and present-tense variantsDetails
groupByVerb()was called directly in a Svelte{#each}template expression, causing it to be re-evaluated on every render cycle. For each tool pair, this triggered:parseToolCall()→JSON.parseon every tool call contentmakePathsRelative()→.includes()+.replaceAll()on path stringsFor sessions with hundreds of tool calls, this resulted in hundreds of these operations on every single reactivity update.
The fix adds a
$derivedthat pre-computes verb groups for all tool groups whengroupedorrepoDirchange. SinceforcePastTenseis a boolean, we cache both variants (past and present tense). The template then selects the appropriate cached variant with a simple conditional.Test plan
🤖 Generated with Claude Code