Skip to content

perf(agent-manager): render terminal output with WebGL and pause hidden terminals - #13406

Merged
marius-kilocode merged 3 commits into
mainfrom
optimize-sidebar-terminal-rendering
Aug 25, 2026
Merged

perf(agent-manager): render terminal output with WebGL and pause hidden terminals#13406
marius-kilocode merged 3 commits into
mainfrom
optimize-sidebar-terminal-rendering

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Streaming terminal output in Agent Manager (background setup scripts, Run/Setup flows) was expensive in two independent ways. The DOM renderer creates one element per cell per row, so sustained output dominated main-thread work with per-cell churn and a layout/style pass per render cycle. Terminals hidden in the background had no sharing benefit either: visibility was toggled with opacity only, so hidden terminals kept their render loop running at full rate for output nobody sees.

This change makes each of those parts cheap:

  • Terminals render with the WebGL renderer, painting the whole viewport in one draw instead of per-cell elements. Falls back to the DOM renderer when WebGL2 is unavailable.
  • PTY chunks are coalesced into one xterm write per animation frame instead of one parse + render schedule per WebSocket message, with a byte cap and watchdog so the batch stays bounded when frames stall.
  • Inactive terminal slots now use display: none. xterm 6's render service observes the screen element, pauses hidden terminals (rAF loop, model updates, GPU draws), and replays a full refresh on reactivation; the existing fit + refresh activation repaint stays as insurance.

Measured on a 7s streaming capture (isolated webview): layout duration 92 ms to ~0 ms, recalc-style 122 ms to ~0 ms, layout count 262 to 2; hidden-terminal streaming dropped from an identical full-rate render pipeline to parser work only. No bundle size change.

Includes the batcher unit tests and the changeset.

Comment thread packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx Outdated
Comment thread packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/SideTerminalPanel.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/render.tsx
Previous Review Summaries (2 snapshots, latest commit 80024c0)

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

Previous review (commit 80024c0)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx 177 WebGL context per never-unmounted terminal, no context-loss fallback
packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx 309 Status term.writeln calls bypass the new write batcher
packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css 4938 display: none drops layout size so hidden PTY output wraps at the wrong cols
Files Reviewed (9 files)
  • .changeset/agent-manager-terminal-render-performance.md - 0 issues
  • bun.lock - 0 issues
  • packages/kilo-vscode/package.json - 0 issues
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-replay.test.ts - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/SideTerminalPanel.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx - 2 issues
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/render.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/replay.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review

Status: 2 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx 177 WebGL context per never-unmounted terminal, no context-loss fallback
packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css 4938 display: none drops layout size so hidden PTY output wraps at the wrong cols
Files Reviewed (9 files)
  • .changeset/agent-manager-terminal-render-performance.md - 0 issues
  • bun.lock - 0 issues
  • packages/kilo-vscode/package.json - 0 issues
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-replay.test.ts - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/SideTerminalPanel.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/render.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/replay.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 96.6K · Output: 15.4K · Cached: 551.2K

Review guidance: REVIEW.md from base branch main

@marius-kilocode

Copy link
Copy Markdown
Collaborator Author

Measured performance improvement

Measured on an isolated VS Code dev build with the self-test harness: 7.2s streaming capture (1500-line script output), webview performance profile.

Metric Before (DOM renderer, opacity-only hidden) After (WebGL + batching + render pause) Improvement
Visible stream: LayoutDuration 92 ms ~0.7 ms −99.2%
Visible stream: RecalcStyleDuration 122 ms ~0 ms ~100%
Visible stream: LayoutCount 262 2 −99.2%
Visible stream: ScriptDuration 132 ms 133 ms 0% (parse-bound, unchanged)
Hidden terminal: ScriptDuration 121 ms 84 ms −30%
Hidden terminal: GPU render work _updateModel, drawElementsInstanced, bufferData, clone none (parser only) 100% eliminated
Page-trace totals (capture window) script 912 ms, layout 287 ms, paint 146 ms script 551 ms, layout 93 ms, paint 68 ms −40% / −67% / −54%
Terminal switch cost untested 4 ms JS, no >50 ms tasks no long tasks

The visible-path win comes from removing browser layout/paint and per-cell DOM churn; the JS parse cost is unchanged because xterm must parse the output regardless. Background terminals now spend no render work on output nobody sees.

@marius-kilocode
marius-kilocode merged commit 534b6a1 into main Aug 25, 2026
33 checks passed
@marius-kilocode
marius-kilocode deleted the optimize-sidebar-terminal-rendering branch August 25, 2026 09:29
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