Skip to content

Avoid unnecessary --numstat diff for incoming changes decorations - #339008

Merged
Ladislau Szomoru (lszomoru) merged 1 commit into
microsoft:mainfrom
tyrielv:fix/incoming-changes-decoration-numstat
Oct 6, 2026
Merged

Ladislau Szomoru (lszomoru) merged 1 commit into
microsoft:mainfrom
tyrielv:fix/incoming-changes-decoration-numstat

Conversation

@tyrielv

Copy link
Copy Markdown
Contributor

Problem and Context

GitIncomingChangesFileDecorationProvider.getIncomingChanges() (in
extensions/git/src/decorationProvider.ts) computes the "Incoming Changes"
file badges by calling repository.diffBetweenWithStats(). That method runs:

git diff --raw --numstat --diff-filter=ADMR -z --find-renames=<threshold>% <ref1>...<ref2> --

The only consumer of the result, collectIncomingChangesFileDecorations(),
reads only change.status, change.uri, and change.originalUri to pick a
badge glyph (added/deleted/renamed/modified). It never reads the
insertions/deletions stats that --numstat computes, so that work is
always discarded.

This code path runs automatically and without debounce whenever
historyProvider.onDidChangeCurrentHistoryItemRefs fires, which happens on
every git write operation and on every VS Code built-in auto-fetch tick
(git.autofetch, default every 180s) for any repository whose checked-out
branch has an upstream.

On a large repository backed by a partial-clone or virtualized-filesystem
remote (e.g. GVFS/VFS for Git), --numstat forces git to read full blob
content for every added/modified/deleted path in the diff range, and each of
those reads is a lazy network fetch rather than a local disk read. We
measured this directly: on such a repository, incoming ranges touching
several thousand files took 60-200+ seconds and pulled thousands of objects
over the network, purely to compute stats that are then thrown away. Because
the handler isn't debounced, repeated ref-change events can also stack up
multiple concurrent invocations of this work.

Changes

  • getIncomingChanges() now calls repository.diffBetween() instead of
    repository.diffBetweenWithStats(). diffBetween() already exists as a
    sibling method, already returns exactly the Change[] shape this caller
    needs (status + uri + originalUri), and builds a cheaper diff with no
    --numstat and no explicit --find-renames flag.
  • No other call sites, types, or configuration (e.g. git.similarityThreshold,
    rename detection) are touched; diffBetweenWithStats() remains available
    and unchanged for its other callers.

Known gaps and deliberate decisions

  • Rename badge may show as added+deleted instead of renamed, for non-default
    git config
    — diffBetween() does not pass
    --find-renames=<git.similarityThreshold>% the way diffBetweenWithStats()
    did, so incoming-change rename detection now falls back to git's own
    diff.renames default instead of the user's configured threshold. With
    default git and VS Code settings (diff.renames on, 50% threshold on both
    sides) the output is identical either way. Only a repository with
    diff.renames explicitly disabled, or a git.similarityThreshold far from
    50%, would see a renamed file decorated as separate added (↓A) and deleted
    (↓D) badges instead of a single renamed (↓R) badge. The set of files
    decorated as "incoming changes" is unaffected either way; only the glyph
    choice for renames can differ, and only for non-default configs. This
    tradeoff was evaluated and accepted to avoid reintroducing the
    --numstat/blob-hydration cost this PR removes. No follow-up is planned; a
    full fix would mean plumbing similarityThreshold into diffBetween(),
    which is a separate, larger change.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 22:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused API substitution preserves the required Change[] data while eliminating unused statistics computation.

Review effort: Balanced
Findings: None

What changed in this PR

Replaces the stats-producing Git diff with a cheaper name/status diff for incoming-change decorations.

Changes:

  • Uses diffBetween() instead of diffBetweenWithStats().
  • Avoids unnecessary --numstat blob processing.
File Description
extensions/​git/​src/​decorationProvider.ts Retrieves only the change metadata required for decoration badges.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tyrielv
Tyrie Vella (tyrielv) force-pushed the fix/incoming-changes-decoration-numstat branch from 1b884d1 to a354b79 Compare September 30, 2026 22:52
@tyrielv
Tyrie Vella (tyrielv) marked this pull request as ready for review September 30, 2026 22:52
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Ladislau Szomoru (@lszomoru)

Matched files:

  • extensions/git/src/decorationProvider.ts

GitIncomingChangesFileDecorationProvider.getIncomingChanges() called
repository.diffBetweenWithStats(), which runs `git diff --numstat`
and computes insertions/deletions for every changed file. The only
caller, collectIncomingChangesFileDecorations(), only reads
change.status/change.uri/change.originalUri to pick a badge glyph and
never reads the stats.

This method runs automatically, with no debounce, whenever the
current or remote history item ref changes - including every
git.autofetch tick (default every 180s) for any repo with an
upstream. On a large repository backed by a partial-clone or
virtualized-filesystem remote, --numstat forces git to read full
blob content for every added/modified/deleted path in the diff
range, and each read can be a lazy network fetch rather than a local
disk read.

Switch to diffBetween(), which already exists and returns exactly
the Change[] shape this caller needs, without --numstat or
--find-renames.
@lszomoru
Ladislau Szomoru (lszomoru) merged commit 2968071 into microsoft:main Oct 6, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 6, 2026
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.

5 participants