Skip to content

Heavy load from excessive git process spawning — GitStatsPoller and diff polling #8343

@kilo-code-bot

Description

@kilo-code-bot

Problem

Users are reporting heavy system load caused by git processes spawned by the Kilo VS Code extension.

Root Cause Analysis

A comprehensive audit of all git invocation points in the codebase identified the GitStatsPoller (5-second polling interval) as the dominant source of sustained git process load.

Primary Culprit: GitStatsPoller (5s interval)

The GitStatsPoller (instantiated in AgentManagerProvider constructor) runs every 5 seconds when enabled (worktrees.length > 0 || panel !== undefined).

Each poll cycle spawns multiple git processes per worktree:

  • git worktree list --porcelain — presence probe
  • git rev-list --left-right --count — ahead/behind per worktree
  • git rev-parse (multiple calls) — branch resolution, tracking branch, remote
  • git config, git branch --show-current, git symbolic-ref — fallback chains
  • git fetch — remote refresh (throttled to 120s, but resolution commands are not)

With 3 worktrees: ~11 git processes every 5 seconds (~132/min)
With 5 worktrees: ~15 git processes every 5 seconds (~180/min)

Plus the CLI backend's own git processes triggered by diffSummary HTTP calls, easily exceeding 200+ git processes/minute.

Secondary: Diff Polling (2.5s interval)

Both DiffViewerProvider and AgentManagerProvider run independent 2.5-second diff polling intervals when their panels are open, triggering additional git commands via the CLI backend.

Key Issues

  • No backoff when idle — polls at the same rate whether the user is actively coding or AFK
  • No visibility check — polls even when the Agent Manager panel is not visible
  • Redundant resolution chainsresolveTrackingBranchresolveRemoteresolveDefaultBranch each spawn multiple sub-commands without caching
  • Linear scaling — load increases proportionally with worktree count

Load Summary

Source Git processes/min When active Scales with
GitStatsPoller ~120-240+ Always (if worktrees exist or panel open) N worktrees
AgentManagerProvider diff poll ~24 (indirect via CLI) When diff tab visible Constant
DiffViewerProvider diff poll ~24 (indirect via CLI) When diff panel open Constant
Worktree creation ~15-20 burst User action One-time

Recommended Fixes

Priority 1: GitStatsPoller Optimization

  1. Increase interval when panel is hidden — 30-60s instead of 5s when Agent Manager panel is not visible/active
  2. Adaptive backoff — if no changes detected across N consecutive polls, progressively increase interval (5s → 10s → 30s → 60s)
  3. Cache resolution chainsresolveRemote(), resolveTrackingBranch(), resolveDefaultBranch() results rarely change; cache with 60s TTL
  4. Batch git operations — use git for-each-ref or combine multiple rev-parse calls into single process spawns
  5. Stop polling when unnecessary — don't poll when no worktrees exist AND panel is closed

Priority 2: Diff Polling

  1. Use filesystem watchers instead of 2.5s setInterval polling
  2. Share diff target resolution between DiffViewerProvider and AgentManagerProvider

Priority 3: Process Spawn Reduction

  1. Consolidate rev-parse calls into single invocations
  2. Consider persistent git subprocess instead of spawning new process per command

Key Files

  • src/agent-manager/GitOps.ts — Core git operations, poller logic
  • src/agent-manager/WorktreeManager.ts — Worktree lifecycle management
  • src/agent-manager/git-transfer.ts — Git state capture & apply
  • src/services/commit-message/index.ts — VS Code git API usage
  • src/KiloProvider.ts — Remote URL resolution

Metadata

Metadata

Labels

bugSomething isn't workingperformancePerformance improvements

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions