Skip to content

perf: skip git diff-stats subprocesses on a clean working tree #561

@Axelj00

Description

@Axelj00

Problem

run_git_status in src-tauri/src/git_info.rs:209 now calls compute_diff_stats on every cache miss to populate the lines-changed badge (#559). But by the time we call it (line 257), we already know modified, staged, and untracked from parsing git status --porcelain=v2 --branch. When all three are 0 — i.e. the working tree is clean against HEAD — git diff --numstat HEAD will produce no output and git ls-files --others --exclude-standard will produce no output. We pay for two subprocess spawns + 3s timeout watchdogs for a guaranteed empty result.

In a typical agent workflow, most panes most of the time look at clean repos (between edits, between commits). With the 3-second cache TTL and multiple panes polling, those wasted spawns add up.

Fix

Short-circuit before calling `compute_diff_stats`:

```rust
let (lines_added, lines_removed) = if modified == 0 && staged == 0 && untracked == 0 {
(0, 0)
} else {
compute_diff_stats(path).unwrap_or((0, 0))
};
```

Doesn't affect correctness — a clean tree has no diff to report. Saves two git subprocess spawns + the IO/parse + the timeout-loop bookkeeping per cache miss, per pane, on clean repos.

Files

  • src-tauri/src/git_info.rs:257

Out of scope

  • Pre-computing diff stats from the porcelain output itself. The porcelain doesn't include line counts, so we'd still need the subprocess for non-clean trees.
  • Replacing compute_diff_stats with a libgit2 implementation. Bigger lift; this is the cheap win.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance improvementspriority: mediumImportant but not urgenttech-debtTechnical debt and code quality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions