Skip to content

perf(ui): defer diff parsing until tool cards expand - #14011

Merged
marius-kilocode merged 1 commit into
mainfrom
perf/diff-card-render
Sep 10, 2026
Merged

perf(ui): defer diff parsing until tool cards expand#14011
marius-kilocode merged 1 commit into
mainfrom
perf/diff-card-render

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Expanding an edit, write, or apply_patch tool card is the most expensive tool-card render in the transcript: each card parses its patch with Pierre and renders a shadow-DOM diff. These cards also did work while collapsed, so a transcript with many of them paid parse cost before the user opened anything.

Why This Change Was Made

Two causes:

  • edit and write built their diff view with createMemo. Solid evaluates a memo eagerly on render, and the always-rendered trigger read it to decide whether to show "Open in Diff Viewer". The patch was therefore parsed even when the card stayed collapsed. The apply_patch trigger parsed every file the same way. These are now cheap presence and @@ checks, and the view is only parsed when the body mounts or the viewer opens.
  • The deferred mount scheduler mounted one tool body per animation frame. An expanded transcript with many diff cards needed one frame per card before everything was visible. Bodies now mount within a per-frame time budget, so cheap bodies mount together and an expensive body ends that frame. The frame is re-armed in finally so a throwing body cannot stall later mounts.

User Impact

  • Collapsed edit, write, and apply_patch cards no longer parse patches, so a transcript with many collapsed diff cards does less work.
  • Expanded diff cards fill in faster because multiple bodies mount per frame instead of one.
  • Behavior is unchanged: expanded cards render the same diff, and "Open in Diff Viewer" still works for edit, write, and apply_patch.

Evidence

Storybook harness (20-card transcript, 420x720, Chromium, 7 loads per arm, paired before/after):

Tool Expanded settleMs before after Change
edit 39.07 14.21 -63.6%
write 24.02 12.125 -49.5%
apply_patch 53.815 26.855 -50.1%

Collapsed Pierre parses in the same harness: edit 1 to 0, write 1 to 0, apply_patch 2 to 0.

Real VS Code (isolated Extension Development Host, Agent Manager, 20-card sessions, instrumented normalize):

  • Collapsed session switching: 20 parses to 0 parses, with 0 diffs-container in both arms.
  • CPU profile over three switches: ScriptDuration 0.1556s to 0.1436s (-7.7%), transient Nodes 1052 to 314 (-70%).
  • Expanded edit, write, and apply_patch render identically, and "Open in Diff Viewer" opens the preview.

Checks: bun run typecheck and bun run lint in packages/kilo-vscode; the opencode annotation checker passes.

Limitations

  • The VS Code session-switch wall-clock comparison is floor-bound: the message list virtualizes and mounts about five cards, so timing was not a reliable signal. The Storybook harness reproduces the expanded-card render cost.
  • The harness reuses one patch per tool, which understates per-card parse cost.

@kilo-code-bot

kilo-code-bot Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • .changeset/defer-diff-card-render.md
  • packages/kilo-ui/src/components/message-part.tsx
  • packages/ui/src/components/basic-tool.tsx

Reviewed by grok-4.6 · Input: 192.5K · Output: 14.5K · Cached: 383.4K

Review guidance: REVIEW.md from base branch main

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.

2 participants