Skip to content

fix(vscode): keep session switching responsive with expanded edit diffs - #14808

Merged
marius-kilocode merged 4 commits into
mainfrom
profile-session-switching-performance
Oct 5, 2026
Merged

marius-kilocode merged 4 commits into
mainfrom
profile-session-switching-performance

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Switching between Agent Manager worktrees was slower when a visible tool card had an expanded inline edit diff. Profiling warm switches over the same transcript showed the switch span growing from about 56 ms with collapsed edit cards to about 92 ms with two expanded cards. Every expanded capture also produced a 50 to 57 ms main-thread long task. The cost was Pierre diff reconstruction and Shiki tokenization running synchronously inside the selection task.

Why This Change Was Made

A remembered-open deferred card previously disabled deferred body mounting on remount, so the virtualizer would not see a collapsed frame and loop. That kept the row stable but forced the whole diff render into the switch.

This change records the measured body size. On remount, it reserves that height immediately while the existing deferred queue builds the body after the first frame, and it suppresses the open animation for the reserved frame. A stale measurement (different width or font) or a changed diff, status, or approval state falls back to the eager path.

User Impact

The target transcript appears within a frame and expanded diffs fill in shortly after, instead of blocking the switch. Collapsed cards are unchanged.

Evidence

Matched captures in an isolated VS Code instance, three runs applied to the same 326-row transcript, one expanded 94-line diff, and identical scroll positions.

Mark (ms after switch begin) Before mean / median After mean / median Mean change
First frame (switch.paint) 79.78 / 77.97 46.71 / 46.31 -41.5%
Shell ready (switch.shell) 76.98 / 75.94 44.99 / 44.58 -41.6%
Diff body ready (edit.body) 77.05 / 76.02 69.38 / 68.68 -10.0%
Settled (switch.settled) 88.76 / 85.02 69.41 / 68.71 -21.8%
Main-thread task inside the switch Before After
Longest task, mean 52.72 ms 34.61 ms
Longest task, median 49.02 ms 34.07 ms
Long tasks over 50 ms 1 of 3 runs 0 of 3 runs

For reference, the first controlled comparison that isolated the cause, mean of three runs:

Card state Switch span
Two collapsed edit cards 56.1 ms
Two expanded edit cards 92.4 ms
Expanded overhead +36.3 ms (+64.8%)

Validation:

  • 73 focused tests pass, including new fixtures for reserved height, deferred cancellation on a rapid switch, and the stale-measurement fallback.
  • Extension typecheck, lint, Knip, merge marker, and workflow checks pass.
  • Manual isolated VS Code checks passed for normal rapid switching, scroll remount, and collapse and reopen.

Limitations: switch.paint is a semantic animation-frame mark, not compositor presentation. Three instrumented runs per variant support this matched workload rather than a general latency guarantee.

Reserve the cached height of a restored open tool card and defer its body mount, so Pierre and Shiki diff work no longer runs inside the Agent Manager session switch. Fall back to the eager path when the cached measurement is missing or stale.
@kilo-code-bot

kilo-code-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/kilo-vscode/tests/fixtures/basic-tool-render.tsx 110 The new measurement/cache logic in the kilo-ui wrapper (ResizeObserver height capture, revision/status/approval cache keys, heights map) still has no runtime coverage; the fixtures exercise only the shared base with a hand-supplied deferredSize.
Files Reviewed (incremental pass)
  • packages/kilo-vscode/tests/unit/kilo-ui-contract.test.ts - no issues (formatting-only change)

Fix these issues in Kilo Cloud

Previous Review Summaries (2 snapshots, latest commit d756c2b)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit d756c2b)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/kilo-vscode/tests/fixtures/basic-tool-render.tsx 110 New measurement/cache logic in the kilo-ui wrapper still lacks runtime coverage; fixtures exercise only the shared base with a hand-supplied deferredSize.
Files Reviewed (3 files)
  • packages/kilo-ui/src/components/basic-tool.tsx - prior warning resolved (revision now fingerprinted via checksum)
  • packages/kilo-vscode/tests/unit/kilo-ui-contract.test.ts - no issues
  • packages/kilo-vscode/tests/fixtures/basic-tool-render.tsx - 1 suggestion (carried forward)

Fix these issues in Kilo Cloud

Previous review (commit 0e470ef)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-ui/src/components/basic-tool.tsx 104 Module-level heights map retains the full revision (patch/content) string for up to 2000 cards and is never cleared on session switch.

SUGGESTION

File Line Issue
packages/kilo-vscode/tests/fixtures/basic-tool-render.tsx 110 New measurement/cache logic in the kilo-ui wrapper has no runtime coverage; fixtures exercise only the shared base with a hand-supplied deferredSize.
Files Reviewed (8 files)
  • .changeset/quick-otters-switch.md - no issues
  • packages/kilo-ui/src/components/basic-tool.css - no issues
  • packages/kilo-ui/src/components/basic-tool.tsx - 1 warning
  • packages/kilo-ui/src/components/message-part.tsx - no issues
  • packages/kilo-vscode/tests/fixtures/basic-tool-render.tsx - 1 suggestion
  • packages/kilo-vscode/tests/unit/basic-tool-render.test.ts - no issues
  • packages/kilo-vscode/tests/unit/kilo-ui-contract.test.ts - no issues
  • packages/ui/src/components/basic-tool.tsx - no issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 49.5K · Output: 5.2K · Cached: 264.2K

Review guidance: REVIEW.md from base branch main

Store a short checksum of the patch instead of the full string, so the cache cannot pin large diff payloads for the webview lifetime. Addresses review feedback.
@marius-kilocode
marius-kilocode merged commit e8f2089 into main Oct 5, 2026
35 checks passed
@marius-kilocode
marius-kilocode deleted the profile-session-switching-performance branch October 5, 2026 14:02
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