Skip to content

fix(staged): memoize groupByVerb to prevent UI freeze on large sessions - #618

Merged
matt2e merged 2 commits into
mainfrom
fix/memoize-verb-group-computation
Apr 14, 2026
Merged

fix(staged): memoize groupByVerb to prevent UI freeze on large sessions#618
matt2e merged 2 commits into
mainfrom
fix/memoize-verb-group-computation

Conversation

@matt2e

@matt2e matt2e commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Pre-compute groupByVerb() results for all tool groups in a $derived block, caching both past-tense and present-tense variants
  • The template now picks the correct tense via a cheap boolean lookup instead of re-running expensive JSON.parse + string replace operations on every render
  • Fixes main thread freezing (heavy String.replace, RegExp.match, string concatenation) when viewing sessions with hundreds of tool calls

Details

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.parse on every tool call content
  • makePathsRelative().includes() + .replaceAll() on path strings

For sessions with hundreds of tool calls, this resulted in hundreds of these operations on every single reactivity update.

The fix adds a $derived that pre-computes verb groups for all tool groups when grouped or repoDir change. Since forcePastTense is a boolean, we cache both variants (past and present tense). The template then selects the appropriate cached variant with a simple conditional.

Test plan

  • Open a session with many tool calls (50+), verify tool cards display correctly (right verb, right detail text, right tense)
  • Verify live sessions show present tense ("Reading", "Running") for pending tool calls
  • Verify completed sessions show past tense ("Read", "Ran") for all tool calls
  • Verify the modal is noticeably more responsive when scrolling through a long session
  • Verify sending a follow-up message correctly switches tense for preceding tool groups

🤖 Generated with Claude Code

@matt2e
matt2e requested review from baxen and wesbillman as code owners April 14, 2026 04:09
matt2e and others added 2 commits April 14, 2026 15:04
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
matt2e force-pushed the fix/memoize-verb-group-computation branch from 843ffd2 to 2773f38 Compare April 14, 2026 05:07
@matt2e
matt2e merged commit 8c134ac into main Apr 14, 2026
6 checks passed
@matt2e
matt2e deleted the fix/memoize-verb-group-computation branch April 14, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant