perf(host-service): bound large git watcher batches

Merged
KI
4mo ago
+525-145

Summary

  • cap exact GitWatcher worktree paths at 128 per debounce batch, then emit the existing broad invalidation signal
  • skip further path normalization after a batch becomes broad
  • update the large-repository profiler to exercise the real worker task, record worker/inline mode and event-loop delay, isolate watcher-only cost, and support multiple real worktrees
  • record the post-implementation measurements and limiter decision in the worker-pool plan

Why

The worker pool moved Git status parsing off the host-service event loop, but large native watcher batches still performed unbounded path normalization and Set growth on the main thread. Profiling showed that adding another worker hop increased latency because of structured-clone and pool-contention costs. Bounded broad invalidation preserves correctness while removing the sustained watcher-loop pressure.

Impact

In representative eight-worktree profiling, watcher-only p99 event-loop delay dropped from 87.2 ms to 13.6 ms. The full watcher plus worker-backed status run dropped from 43.5 ms to 6.3 ms p99 and from 7.91 s to 5.34 s. Concurrency 6 did not improve completion time and increased active Git processes, so the production limiter remains at 4.

Validation

  • bun run lint:fix
  • bun run lint
  • bun run --cwd packages/host-service typecheck
  • bun run --cwd packages/host-service build:host
  • 30 focused GitWatcher, worker-pool, limiter, and worker-import tests

Summary by CodeRabbit

  • Documentation
    • Added a plan detailing phased rollout for moving Git status processing off the shared event loop, including worker fallback behavior, bundling guidance, and parity/testing risks.
  • Improvements
    • Updated Git watcher debounce batching to cap collected paths; exceeding the limit now triggers broad refresh signaling (no per-path payload).
    • Enhanced Git status profiling to run via the host worker pool and report worker-vs-inline execution with event-loop delay metrics, including workspace sharding.
  • Tools / Testing
    • Added new profiling flags (--workspaces, --watcher-only) and expanded worker/inline execution parity and worker behavior coverage.