Skip to content

perf(agent-manager): optimize worktree diff loading - #13411

Merged
marius-kilocode merged 12 commits into
mainfrom
optimize-worktree-diff-loading
Aug 25, 2026
Merged

perf(agent-manager): optimize worktree diff loading#13411
marius-kilocode merged 12 commits into
mainfrom
optimize-worktree-diff-loading

Conversation

@marius-kilocode

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

Copy link
Copy Markdown
Collaborator

Summary

Agent Manager worktree review switching rebuilt the entire diff surface and repeated Git work for every detail request. This change retains recently rendered review panels and removes redundant work from the extension-host diff path, while preserving the stacked review UX, complete file loading, comments, Markdown rendering, image handling, and live polling.

Performance

Measurements were collected with the VS Code self-test harness against an ephemeral shadow/fixture workspace containing real worktree diffs. The same Agent Manager surface, worktree cards, and completion checks were used for before/after captures where the worktree remained stable.

Scenario Before After Change
Cold seven-file diff, fully rendered 942 ms 480 ms 49% faster, about 2.0x
Warm A-B-A switch, complete rendered diff 144-169 ms about 46 ms 68-73% faster, about 3.1-3.7x
Warm diff DOM churn 4,678 nodes 117 nodes 97.5% lower
Warm switch heap allocation 9.3 MB 3.1 MB about 67% lower
Heavy render script time 390 ms 163 ms about 58% lower
Largest heavy render task 249 ms 116 ms about 54% shorter
Animated loading states Present None Removed

The original heavy worktree changed while its owning Agent Manager session was active, so later heavy cold captures are not byte-identical. The final cold seven-file capture is therefore the conservative cold comparison. The warm measurement directly verified the retained DOM, no loading state, no spinner, complete diff hosts, and scroll preservation.

Behavior

  • Retains up to four recent project-and-scope-qualified diff panels without unmounting their Virtua/Pierre state.
  • Preserves expanded files and scroll position across worktree switches.
  • Keeps comments and review composers isolated by project and composite diff scope.
  • Reuses summary metadata and caches exact file details with bounded count and byte limits.
  • Cancels queued and running obsolete Git detail processes when switching contexts.
  • Prevents overlapping diff polling fetches.
  • Removes animated summary and per-file loading spinners.
  • Keeps large-file limits, hunk-bounded patches, untracked files, images, Markdown rendering, and live stale-detail refresh behavior unchanged.

Comment thread packages/kilo-vscode/src/agent-manager/local-diff.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/diff-viewer/diff-requests.ts
Comment thread packages/kilo-vscode/webview-ui/agent-manager/DiffPanelCache.tsx
Comment thread packages/kilo-vscode/webview-ui/agent-manager/review-composers.ts
@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 (1 file)
  • packages/kilo-vscode/src/agent-manager/local-diff.ts
Previous Review Summaries (7 snapshots, latest commit bf07f65)

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

Previous review (commit bf07f65)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx

Previous review (commit 7230c71)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 file)
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx

Previous review (commit 71211f1)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • packages/kilo-vscode/src/agent-manager/semaphore.ts
  • packages/kilo-vscode/src/diff/SourceController.ts
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-diffs.ts

Previous review (commit 5fea23b)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • packages/kilo-vscode/src/agent-manager/local-diff.ts
  • packages/kilo-vscode/src/diff/SourceController.ts
  • packages/kilo-vscode/tests/unit/source-controller.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/DiffPanel.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-diffs.ts

Previous review (commit befab09)

The review did not run because the selected model is no longer available.

Choose another model in Kilo Code review settings: https://app.kilo.ai/code-reviews

Previous review (commit befab09)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/worktree-diffs.ts 158 Merge reads project() but writes ev.projectId
packages/kilo-vscode/src/agent-manager/local-diff.ts 362 Cache hits re-read and hash the entire working file
packages/kilo-vscode/webview-ui/agent-manager/DiffPanel.tsx 163 Activating a cached panel can wipe a shared composer draft
packages/kilo-vscode/src/diff/SourceController.ts 271 Coalesced fetches can skip the post-revert refresh
Files Reviewed (15 files)
  • packages/kilo-vscode/src/agent-manager/local-diff.ts - 1 issue
  • packages/kilo-vscode/src/diff/SourceController.ts - 1 issue
  • packages/kilo-vscode/tests/unit/agent-manager-worktree-diffs.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/git-ops.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/local-diff.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/source-controller.test.ts - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/DiffPanel.tsx - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/DiffPanelCache.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/apply-to-local.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/project/review-state.ts - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/revert-file.ts - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/review-composers.ts - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-diffs.ts - 1 issue
  • packages/kilo-vscode/webview-ui/diff-viewer/diff-requests.ts - 0 issues

Fix these issues in Kilo Cloud

Previous review (commit ea74bda)

Status: 4 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/kilo-vscode/src/agent-manager/local-diff.ts 328 Aborted/failed detail fetches can be cached as empty diffs
packages/kilo-vscode/webview-ui/diff-viewer/diff-requests.ts 39 Warm switch-back does not retry cancelled detail requests
packages/kilo-vscode/webview-ui/agent-manager/DiffPanelCache.tsx 94 Inactive cached panels can clobber the shared review composer

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/review-composers.ts 15 clear() is never called, so composers grow without bound
Files Reviewed (21 files)
  • .changeset/fast-agent-manager-diffs.md - 0 issues
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts - 0 issues
  • packages/kilo-vscode/src/agent-manager/GitOps.ts - 0 issues
  • packages/kilo-vscode/src/agent-manager/local-diff.ts - 1 issue
  • packages/kilo-vscode/src/agent-manager/semaphore.ts - 0 issues
  • packages/kilo-vscode/src/diff/SourceController.ts - 0 issues
  • packages/kilo-vscode/src/diff/sources/catalog.ts - 0 issues
  • packages/kilo-vscode/src/diff/sources/worktree.ts - 0 issues
  • packages/kilo-vscode/tests/unit/agent-manager-arch.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/agent-manager-worktree-diffs.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/local-diff.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/semaphore.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/source-controller.test.ts - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/DiffPanel.tsx - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/DiffPanelCache.tsx - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/revert-file.ts - 0 issues
  • packages/kilo-vscode/webview-ui/agent-manager/review-composers.ts - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/worktree-diffs.ts - 0 issues
  • packages/kilo-vscode/webview-ui/diff-viewer/diff-requests.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 131K · Output: 10.7K · Cached: 215.3K

Review guidance: REVIEW.md from base branch main

Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-diffs.ts Outdated
Comment thread packages/kilo-vscode/src/agent-manager/local-diff.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/agent-manager/DiffPanel.tsx Outdated
Comment thread packages/kilo-vscode/src/diff/SourceController.ts
@WebReflection
WebReflection self-requested a review August 25, 2026 12:27
Comment thread packages/kilo-vscode/src/agent-manager/local-diff.ts Outdated
Comment thread packages/kilo-vscode/src/agent-manager/semaphore.ts Outdated
Comment thread packages/kilo-vscode/src/agent-manager/semaphore.ts Outdated
Comment thread packages/kilo-vscode/src/diff/SourceController.ts Outdated
Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-diffs.ts Outdated
@marius-kilocode

Copy link
Copy Markdown
Collaborator Author

thanks @WebReflection

@iscekic iscekic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, ignorable bot remarks below

Comment thread packages/kilo-vscode/webview-ui/agent-manager/worktree-diffs.ts
@marius-kilocode
marius-kilocode merged commit 4a823c0 into main Aug 25, 2026
24 checks passed
@marius-kilocode
marius-kilocode deleted the optimize-worktree-diff-loading branch August 25, 2026 15:32
@marius-kilocode

Copy link
Copy Markdown
Collaborator Author

Updated performance results

The latest optimization replaces two separate tracked-file scans, git diff --name-status and git diff --numstat, with one git diff --raw --numstat command. This removes a full repository scan and reduces contention in the shared Git process queue without changing diff content, file statuses, line counts, images, or review behavior.

Measured in the same isolated VS Code instance against the same 12-file worktree, with a cold extension process and all file details loaded:

Metric Before After Improvement
Diff summary available 556 ms 350 ms 37% faster
All 12 file details loaded 1,200 ms 574 ms 52% faster
Diff panel first visible 9 ms 8 ms No meaningful change
Renderer JavaScript 62 ms 56 ms Not the main bottleneck
Git summary subprocesses 4 3 One fewer full Git scan

The earlier figures in the PR description used a different seven-file scenario: 942 ms to 480 ms cold, and 144-169 ms to about 46 ms for warm A-B-A switching. The new 12-file measurements are a separate before/after comparison for the additional Git-scan optimization, not a direct replacement for that seven-file baseline.

Warm cached panel reopening remains approximately 4 ms. The remaining cold-load cost is primarily the separate per-file Git detail operations; batching those requests is tracked in #13415.

Validation: all 4,153 extension unit tests pass, along with lint, both typechecks, Knip, and manual verification of complete diff rendering and warm worktree switching.

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.

3 participants