Skip to content

perf(vscode): cut session switch and send latency in chat transcript - #14237

Merged
marius-kilocode merged 2 commits into
mainfrom
profile-session-switch-performance-regression-vsco
Sep 17, 2026
Merged

marius-kilocode merged 2 commits into
mainfrom
profile-session-switch-performance-regression-vsco

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Switching between sessions in Agent Manager and sending a prompt both pause the transcript. The pause is most visible when the previous turn has many tool calls and the transcript is scrolled to the bottom.

Why This Change Was Made

Profiling the isolated VS Code extension with a real session history (201 messages, 209 tool calls, all tool and reasoning blocks collapsed) showed the cost before the provider is even contacted:

  • Optimistic insertion of the user message recreated the whole retained turn under the virtualizer owner, which re-created collapsed tool rows and forced a layout.
  • The submission state update rendered separately from the optimistic message, so Send produced an intermediate transcript paint.
  • Restoring a session reset the prompt textarea height and then read scrollHeight, forcing layout even when the draft was empty, and rebuilt a model-key set while scanning an empty draft.

This change keeps the whole live turn rendered directly, which is what prevents flicker during streaming, and instead reuses the already mounted row across the direct and virtual owners. The row keeps its DOM and component instance, so the handoff no longer re-creates it. The optimistic message and submission state now update in one batch. Empty drafts skip the layout read and the mention and model-catalog scans, while non-empty autosize behavior is unchanged.

User Impact

  • Sending a prompt after a tool-heavy turn is faster, and the transcript stays pinned with no flicker or blank frame.
  • Switching sessions does less forced layout and style recalculation.
  • Empty and wrapped prompt drafts keep their previous appearance and autosize.

Evidence

Isolated VS Code self-test, real session history imported read-only, tools collapsed, reasoning set to Headline.

Scenario Before After
Switch to the heavy session, second animation frame (4 warm samples) 53.6 / 42.5 / 37.5 / 36.9 ms 58.5 / 38 / 35.5 / 32.5 ms
Switch style recalculation in the profile 0.219 s 0.164 s
Send after a completed 15-tool turn, input cleared 27.8 ms 16.5 ms
Send after a completed 15-tool turn, second animation frame 53.1 ms 43.0 ms
Send after a short turn, input cleared 21.3 ms 15.7 ms

Flicker checks after the change:

  • Streaming a 15-tool turn: 665 sampled frames, no frame with a bottom-offset jump over 4 px, maximum 0.5 px, last-row offset constant.
  • Sending the next prompt while the completed turn hands off: 286 frames, no jump over 4 px, maximum 2 px, transcript never emptied, no duplicate rows.
  • Empty input stays 54 px, matching the before screenshot; a 200-character wrapped draft grows to 89 px.

Checks: bun run compile (host and webview typecheck, lint, bundle), focused transcript, scroll, prompt, and mention unit tests, check-kilocode-change, and knip.

Limitations

The switching improvement is small and within sample noise, and the profile only confirms that the solid-presence animation-name hot path left the top list. No build of the previous revision was compared, so the historical regression size is not proven. The absolute Send baseline differs between sessions, so the Send percentages are relative to this fixture.

marius-kilocode and others added 2 commits September 17, 2026 13:13
Batch the optimistic user message with submission state so Send does not
render an intermediate transcript, and reuse a mounted row's DOM when it
moves between the direct tail and the virtualizer. Skip the forced
scrollHeight read and the mention/model catalog scan for empty drafts.
Comment thread packages/kilo-vscode/webview-ui/src/components/chat/MessageList.tsx
Comment thread packages/kilo-vscode/tests/fixtures/transcript-row-handoff.tsx
@kilo-code-bot

kilo-code-bot Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 3 Issues Found | Recommendation: Merge (non-blocking suggestions)

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 3

No correctness or behavioral regressions were found in the changed production code. The batch() in submit, the empty-draft short-circuits in useFileMention, the adjustHeight empty path, and the createRowHandoff disposal lifecycle all check out as behavior-preserving; the fixture exercises the real handoff and its identity/mount/cleanup assertions are discriminating.

Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/src/components/chat/transcript-row-handoff.ts 16 entries.set runs after render(), so a throw orphans the root and no cleanup can reach it
packages/kilo-vscode/webview-ui/src/components/chat/MessageList.tsx 813 Eager lookup().get(key)! can throw before the documented removed-row fallback applies
packages/kilo-vscode/tests/fixtures/transcript-row-handoff.tsx 87 Context-inheritance assertion cannot fail as written
Files Reviewed (11 files)
  • .changeset/session-switch-send-responsiveness.md
  • packages/kilo-docs/public/img/screenshot-tests/kilo-vscode/visual-regression/agentmanager/readable-chat-420-chromium-linux.png
  • packages/kilo-docs/public/img/screenshot-tests/kilo-vscode/visual-regression/chat/welcome-with-switcher-and-notification-chromium-linux.png
  • packages/kilo-vscode/tests/fixtures/transcript-row-handoff.tsx - 1 issue
  • packages/kilo-vscode/tests/unit/transcript-row-handoff.test.ts
  • packages/kilo-vscode/tests/unit/use-file-mention.test.ts
  • packages/kilo-vscode/webview-ui/src/components/chat/MessageList.tsx - 1 issue
  • packages/kilo-vscode/webview-ui/src/components/chat/PromptInput.tsx
  • packages/kilo-vscode/webview-ui/src/components/chat/transcript-row-handoff.ts - 1 issue
  • packages/kilo-vscode/webview-ui/src/context/session.tsx
  • packages/kilo-vscode/webview-ui/src/hooks/useFileMention.ts

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

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