Skip to content

fix(git): avoid repeated full repository scans - #353

Merged
fcoury merged 1 commit into
mainfrom
fcoury/git-refresh-scheduling
Aug 27, 2026
Merged

fcoury merged 1 commit into
mainfrom
fcoury/git-refresh-scheduling

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

The Git plugin refreshed status every five seconds by cancelling any scan still running and starting another. In large repositories, where a scan can take much longer than five seconds, that can keep CPU usage high and prevent status from completing even with the dashboard closed. Opening a clean dashboard also launched a full diff-statistics scan with no tracked changes to display.

This change lets each status scan finish and coalesces refresh requests received while it runs into one follow-up. Periodic polling resumes after completion, with a cooldown of at least five seconds and nine times the scan duration. Unchanged results and failures also increase the minimum delay up to 60 seconds; the duration-based cooldown can exceed that limit. Explicit refreshes bypass the idle cooldown.

Failed scans retain the last successful status and show a stale warning. Retry timers survive process-launch failures, stale status and repository-discovery events are ignored after repository changes, and shutdown cancels pending status work. Working-tree diff statistics run only for staged or unstaged sections containing tracked changes; commit-view statistics remain available.

Host API 0.17 adds MonotonicTime for elapsed-time measurements, while retaining compatibility with 0.16 packages. The schema, compatibility documentation, and focused plugin CI tests are updated together.

How to Test

  1. Run the focused tests on Unix:

    cargo test --release --all-features --lib git_refresh -- --test-threads=1
    cargo test --release --all-features --lib monotonic_time_ -- --test-threads=1

    The gated-process tests verify that slow scans survive old poll events, refresh bursts produce one follow-up, and cooldown grows with scan duration. git_refresh_failed_output_preserves_the_last_successful_status verifies cached rows survive failures and the stale warning clears on recovery. The remaining cases cover launch retries, repository changes, shutdown, and statistics selection.

  2. Build with cargo build --release. In a disposable Git repository with a committed file, modify that file and add an untracked file. Launch target/release/red --root <repository> and run :GitDashboard. Both changes should appear, with diff counts for the tracked file. Add another file externally and press r; it should appear promptly during the idle cooldown.

  3. Open the dashboard in a clean repository and inspect the editor's Git child processes. Status should complete without starting git diff --numstat. In a repository where status takes longer than five seconds, the same status process should run to completion. Repeated r presses while it runs should queue only one subsequent scan. Once pending work finishes, [git-status] completed log entries should report a cooldown of at least nine times the scan duration. Press q to close the dashboard; background polling should retain that scheduling policy. Exit the editor with :q!.

Validation at f63343cbe1bb4ca204a1b404da7a38fd8cc4686a: 3,542 tests passed across 24 targets, with two ignored. The full run had one detached IPC timeout; all four tests in that target passed on an isolated retry without source changes. Release Clippy passed for all targets and features with warnings denied; formatting and Markdown links also passed.

In a live large-repository smoke test, two status scans completed in about 69.7 seconds each and scheduled roughly 627 seconds of cooldown, with no overlapping status scans. During approximately 15-second observations with the dashboard closed and then open, there were no Git children and Red averaged under 0.4% of one CPU. These were short cooldown observations, not measurements over the full scheduled interval. Active scans still use multiple cores; this change reduces repeated background work rather than imposing a CPU cap.

Let status scans finish, coalesce pending refreshes, and schedule idle polls
after a cooldown based on scan duration. Preserve cached status across
failures and cancel pending work on shutdown or repository changes.

Skip diff statistics for empty tracked sections so opening a clean
dashboard does not launch another full worktree scan.
@fcoury
fcoury merged commit 873bbae into main Aug 27, 2026
14 checks passed
@fcoury
fcoury deleted the fcoury/git-refresh-scheduling branch August 27, 2026 23:51
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