Skip to content

fix(vscode): stop hidden polling and reuse diff file counts - #13795

Merged
marius-kilocode merged 3 commits into
mainfrom
investigate-watcher-cpu-usage
Sep 4, 2026
Merged

fix(vscode): stop hidden polling and reuse diff file counts#13795
marius-kilocode merged 3 commits into
mainfrom
investigate-watcher-cpu-usage

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Changes/Review still reread every eligible untracked text file on each 2.5-second summary poll, including while the panel was hidden. Standalone Kilo editor tabs also kept separate 5-second stats pollers active when hidden. The badge cache added in #13728 did not cover the review-summary path, and sequential scans above its 10,000-entry capacity could evict and reread the entire working set on every pass.

Fixes #13720.

Why This Change Was Made

Pause diff and standalone-chat stats polling while the owning view is hidden, including initial hidden activation. Preserve the selected diff source and activation options, then refresh when the view becomes visible. An already-running scan can finish, but it cannot restart the hidden polling timer.

Share metadata-keyed line counts and binary classification between review summaries, individual untracked-file metadata, and badges. Keep the existing 16-operation read limit, 10,000-entry cache limit, and 1,000,000-byte line-count cutoff. Once the cache is full, admit one new path per 16 misses instead of allowing a sequential scan to replace every cached entry. Changed resident entries are still updated immediately; totals are not truncated. Failed binary probes are not cached, and metadata is rechecked after probing so a file that grows beyond the cutoff is not fully read.

User Impact

Visible diffs and badges continue to update. Changes made while a view is hidden appear when it is reopened. Diff totals and text, binary, empty-file, oversized-file, and symlink handling are covered by regression tests.

This reduces repeated file work, not all repository activity: Git status and metadata scans remain. Over-capacity working sets still require some reads. New repositories warm more slowly when the shared cache is already full. No new setting or feature removal is involved.

Evidence

Exact Node summary measurements

macOS arm64, Node v25.2.1. Two separate Node bundles used the same createLocalDiff(...).summary() workload: the baseline source from 86c1928c4a and the final patch at 5134625384. The paired run was repeated after the binary-probe recovery and metadata revalidation corrections. Each disposable Git repository contained 512 unchanged untracked text files, each 163,840 bytes and 8,192 lines: 83,886,080 bytes (80 MiB) total. Each pass returned 512 files and 4,194,304 added lines in both versions.

CPU is Node process user + system CPU time, not wall time or whole-VS-Code CPU utilization. Times below are the recorded values rounded to milliseconds. Full-file reads count fs.readFile calls; Git work and binary-probe reads are separate.

Pass Before full-file reads After full-file reads Before CPU (ms) After CPU (ms) Before elapsed (ms) After elapsed (ms) Before max event-loop delay (ms) After max event-loop delay (ms)
Cold 512 512 259 290 172 190 12 12
Warm 1 512 0 205 17 170 41 12 10
Warm 2 512 0 189 14 163 40 13 10
Warm 3 512 0 213 15 169 41 14 10
  • Median warm CPU: 205 ms to 15 ms, a 190 ms reduction (92.68%).
  • Median warm elapsed time: 169 ms to 41 ms, a 128 ms reduction (75.74%).
  • Cold-pass trade-off in this run: CPU increased 259 ms to 290 ms and elapsed time increased 172 ms to 190 ms. Cold reads now include the metadata safety recheck; warm cache hits avoid it.
  • Warm full-file reads: 512 to 0, removing 80 MiB of full-file reads per scan. Cold reads remain necessary.
  • Event-loop delay was sampled at 10 ms resolution. These are short synthetic samples, not a claim that the original 55-worktree environment or its sustained 100% CPU was reproduced.

Exact cache-capacity measurements

Real 8 KiB text files, three consecutive scans, with unchanged totals:

Working set Before reads per pass After reads per pass
9,000 files 9,000 / 0 / 0 9,000 / 0 / 0
11,000 files 11,000 / 11,000 / 11,000 11,000 / 1,065 / 1,065

For the 11,000-file case, warm scans perform 9,935 fewer full-file reads (90.32%), reducing full-file bytes read from 90,112,000 to 8,724,480 per scan. These read counts were reverified after the final probe-safety corrections. Switching to a different 11,000-file root with an already-full cache produced 11,000 / 10,312 / 9,668 reads in the patched version, showing the slower but progressive warm-up trade-off.

Functional verification

  • Final extension unit suite: 4,866 passed, 1 skipped, 0 failed, across 383 files, both locally and in CI. Local duration: 137.66 s; CI test duration: 42.01 s.
  • Final corrections: compile (host/webview typechecks, lint, and bundles), 77 focused file/cache tests, and the two independently reproduced probe/growth regressions passed. Knip, formatting, and the Kilo change-marker guard passed.
  • All applicable CI checks passed at commit 5134625384. Automated review reported no issues; there are no unresolved review threads. The two independent local review findings were fixed and retested before enabling auto-merge.
  • Isolated VS Code: Agent Manager review and standalone Changes both showed edits made while hidden after reopening. Native chat hide/show retained its input view. Before/after renderer traces were captured for the same review-to-file transition; these renderer traces are not used as extension-host CPU measurements.

The screenshot shows an untracked file refreshed to two lines after editing it while review was hidden. It contains only disposable fixture data.

Review refreshes an untracked file to two added lines after an edit made while the panel was hidden

@kilo-code-bot

kilo-code-bot Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files)
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts
  • packages/kilo-vscode/src/agent-manager/worktree-diff-controller.ts
  • packages/kilo-vscode/src/diff/DiffViewerProvider.ts
Previous Review Summaries (2 snapshots, latest commit 5134625)

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

Previous review (commit 5134625)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (14 files)
  • .changeset/quiet-hidden-diff-polling.md
  • packages/kilo-vscode/src/KiloProvider.ts
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts
  • packages/kilo-vscode/src/agent-manager/git-stats-snapshot.ts
  • packages/kilo-vscode/src/agent-manager/local-diff.ts
  • packages/kilo-vscode/src/agent-manager/worktree-diff-controller.ts
  • packages/kilo-vscode/src/diff/DiffViewerProvider.ts
  • packages/kilo-vscode/src/diff/SourceController.ts
  • packages/kilo-vscode/src/diff/shared/binary.ts
  • packages/kilo-vscode/tests/unit/git-stats-snapshot.test.ts
  • packages/kilo-vscode/tests/unit/kilo-provider-acknowledgement.test.ts
  • packages/kilo-vscode/tests/unit/local-diff.test.ts
  • packages/kilo-vscode/tests/unit/source-controller.test.ts
  • packages/kilo-vscode/tests/unit/worktree-diff-controller.test.ts

Previous review (commit 2fd7123)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (13 files)
  • .changeset/quiet-hidden-diff-polling.md
  • packages/kilo-vscode/src/KiloProvider.ts
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts
  • packages/kilo-vscode/src/agent-manager/git-stats-snapshot.ts
  • packages/kilo-vscode/src/agent-manager/local-diff.ts
  • packages/kilo-vscode/src/agent-manager/worktree-diff-controller.ts
  • packages/kilo-vscode/src/diff/DiffViewerProvider.ts
  • packages/kilo-vscode/src/diff/SourceController.ts
  • packages/kilo-vscode/tests/unit/git-stats-snapshot.test.ts
  • packages/kilo-vscode/tests/unit/kilo-provider-acknowledgement.test.ts
  • packages/kilo-vscode/tests/unit/local-diff.test.ts
  • packages/kilo-vscode/tests/unit/source-controller.test.ts
  • packages/kilo-vscode/tests/unit/worktree-diff-controller.test.ts

Reviewed by grok-4.6 · Input: 261.6K · Output: 10.8K · Cached: 323.5K

Review guidance: REVIEW.md from base branch main

Comment thread packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts Outdated
Comment thread packages/kilo-vscode/src/agent-manager/worktree-diff-controller.ts Outdated
Comment thread packages/kilo-vscode/src/diff/DiffViewerProvider.ts Outdated
@marius-kilocode
marius-kilocode merged commit 3593340 into main Sep 4, 2026
25 checks passed
@marius-kilocode
marius-kilocode deleted the investigate-watcher-cpu-usage branch September 4, 2026 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants