Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): avoid expensive diff minimization in status refreshes #21872

Mergedvoltcrash(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/21872/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Problem

Status refreshes and run finalization calculate Changes totals with git diff --numstat --minimal. On a branch with a large diff, #21858 reports that this calculation alone takes about 21 seconds.

Change

Move --minimal out of the shared review arguments and add it explicitly to the detailed review diff path. Status totals use Git's configured algorithm; review statistics and patches retain their current behavior. Totals can differ from the minimal review counts for ambiguous repeated lines.

Add a regression test using real Git and repeated lines that distinguish the two algorithms. It checks status totals against the default diff and review statistics against the minimal diff.

Scope and approval

Fixes #21858. The scope follows the maintainer acceptance of the --minimal fix. Refresh deduplication remains tracked separately in #7076.

Two server files, 49 additions and 1 deletion (50 changed lines, including tests). The production change moves one flag. Shared server status serves web, desktop, mobile, and remote connections without client or contract changes.

Verification

  • The new regression failed before the fix: Changes totals used +964/-964 instead of Git's default +1008/-1008. It passes after the fix and also checks that review statistics stay minimal.
  • From apps/server: vp test run src/vcs/GitVcsDriverCore.test.ts src/vcs/GitVcsDriver.test.ts — 229 tests passed. Existing coverage includes configured bases, renames, untracked files, and unborn HEAD handling.
  • vp run --filter t3 typecheck — passed (existing Effect suggestions only).
  • vp lint apps/server/src/vcs/GitVcsDriverCore.ts apps/server/src/vcs/GitVcsDriverCore.test.ts --report-unused-disable-directives — no errors; two existing warnings on untouched lines.
  • vp fmt --check apps/server/src/vcs/GitVcsDriverCore.ts apps/server/src/vcs/GitVcsDriverCore.test.ts and git diff --check — passed.

On Linux arm64 with Git 2.56.0, a synthetic 40,000-line repeated-content fixture took 3.599s median with --minimal versus 0.133s without it across three runs (about 27x faster). Numstat changed from +24,185/-24,185 to +24,690/-24,690, illustrating the documented count tradeoff. These are command timings, not an end-to-end desktop measurement; I did not have the reporter's repository or reproduce their macOS timings.

Reproduce the command benchmark with Python 3 and Git
import json, pathlib, platform, random, statistics, subprocess, tempfile, time

def git(root, *args):
    return subprocess.run(["git", "-C", str(root), *args], check=True, capture_output=True, text=True).stdout

with tempfile.TemporaryDirectory(prefix="t3-21858-benchmark-") as directory:
    root = pathlib.Path(directory)
    git(root, "init", "-b", "main")
    git(root, "config", "user.name", "Benchmark")
    git(root, "config", "user.email", "benchmark@example.com")
    git(root, "config", "diff.algorithm", "myers")
    rng = random.Random(21858)
    path = root / "repeated.txt"
    path.write_text("".join(f"{rng.randrange(16)}\n" for _ in range(40000)))
    git(root, "add", ".")
    git(root, "-c", "commit.gpgsign=false", "commit", "-m", "base")
    path.write_text("".join(f"{rng.randrange(16)}\n" for _ in range(40000)))
    args = ["diff", "--find-renames", "--no-color", "--no-ext-diff", "--no-textconv", "--src-prefix=a/", "--dst-prefix=b/"]
    measurements = {"minimal": [], "default": []}
    outputs = {}
    for run in range(3):
        for kind in (["minimal", "default"] if run % 2 == 0 else ["default", "minimal"]):
            start = time.perf_counter()
            outputs[kind] = git(root, *args, *(["--minimal"] if kind == "minimal" else []), "--numstat", "-z", "HEAD", "--")
            measurements[kind].append(time.perf_counter() - start)
            print(json.dumps({"run": run + 1, "algorithm": kind, "seconds": measurements[kind][-1]}), flush=True)
    print(json.dumps({"platform": platform.platform(), "git": git(root, "--version").strip(), "lines_per_version": 40000, "seconds": measurements, "median_seconds": {key: statistics.median(value) for key, value in measurements.items()}, "numstat": outputs}, indent=2), flush=True)

Implemented with gpt-6.1-sol using the Codex harness in T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Approved at ff03f24

      Macroscope's review found this PR approvable — This is a focused server bug fix: status totals avoid expensive diff minimization while review previews retain their existing minimal-diff behavior. A regression test covers both paths, with no schema, deployment, security, billing, or static-analysis changes.

      Notes:

      • Code review disabled. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 228660a9-10a0-4e2e-8bb6-a7c9612f2e1d
      📥 Commits

      Reviewing files that changed from the base of the PR and between 1c027af941e59000581ca74bfa63f0fe64fa4041 and 33f6ad812d5e12bebf88b18a294b37390cfa13b8.

      📒 Files selected for processing: 2
      • apps/server/src/vcs/GitVcsDriverCore.test.ts
      • apps/server/src/vcs/GitVcsDriverCore.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

      📝 Walkthrough

      The change removes --minimal from branch-change total calculations and applies it to review-preview diffs. Integration coverage verifies default-algorithm totals and minimal-algorithm preview statistics and patches.

      Changes: Review preview diff behavior

      Layer / File(s)Summary
      Scope minimal diff calculation to previews
      apps/server/src/vcs/GitVcsDriverCore.ts, apps/server/src/vcs/GitVcsDriverCore.test.ts
      REVIEW_DIFF_ARGS no longer includes --minimal. getReviewDiffPreview adds the flag to its diff arguments. Tests compare branch-change totals with Git’s default algorithm and preview statistics and patches with --minimal.

      Priority: ➖ Normal

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 33f6a

      No actionable merge-blocking issue remains; the change is ready to merge after normal checks.

      Architecture risk: 🔵 Low · up to ff03f

      The change affects 1 system.

      Changed systems: apps/server

      Architecture concerns No architecture-level concerns identified.

      Review details

      Systems and components

      • observed — apps/server (service) was modified; 2 changed files map to changed impact.

      Before / after behavior

      • observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.test.ts: Adds tests asserting that a bare-repository-shaped project folder does not run its fsmonitor command, and that branch-change totals use default git diff --numstat counts while review preview file statistics match git diff --minimal --numstat under a configured Myers algorithm.
      • observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.ts: Removed --minimal from REVIEW_DIFF_ARGS.
      • observed — Modified behavior in apps/server/src/vcs/GitVcsDriverCore.ts: Added --minimal to the diff arguments used by getReviewDiffPreview.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Description checkPassedThe description includes all required sections. It explains the problem, implementation, scope and approval, regression coverage, test results, benchmark limits, and agent details.
      Title checkPassedThe title clearly and concisely describes the main server fix: avoiding expensive minimal diff computation during status refreshes.
      Linked Issues checkPassedFor #21858, --minimal is removed from REVIEW_DIFF_ARGS, so status change totals use Git's configured algorithm. The detailed review path adds --minimal, so review statistics and patches retain m…
      Out of Scope Changes checkPassedThe reviewed changes contain one production flag relocation and a regression test for #21858. The changes do not add client, contract, or unrelated feature work.
      Full details: Linked Issues check

      Explanation

      For #21858, --minimal is removed from REVIEW_DIFF_ARGS, so status change totals use Git's configured algorithm. The detailed review path adds --minimal, so review statistics and patches retain minimal-diff behavior. The supplied regression-test summary states that real Git compares default and minimal --numstat results for both paths. The separate refresh-deduplication suggestion is outside this accepted fix and is tracked in #7076.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.

Sign in to join this conversation.