Skip to content

Every Diff panel patch for a tracked file on Windows first runs git ls-files --others for that path: 1 of 3 git and ~290 ms of a 0.9 s request #40279

Closed

Description

@juliusmarminge

What is slow

When the Diff panel opens, it requests the patch of each visible file (review.getDiffPreview with file). The file can be a tracked, modified file, already listed as such by the preview. The server still starts by running git ls-files --others --exclude-standard -z -- <path> to see whether it is untracked. It only then runs diff --stat and diff for the patch, and they wait for the listing. With 4 patches requested at once, that wait is about a third of the time before each file's diff appears.

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on. Commit 0fd4822887, server from source serving the production web build. Headless Chromium through Playwright.
  • Seed: git clone --local of this repository (~32k tracked files), git remote remove origin, branch feature-1 with one commit. Then 8 folders x 50 new untracked .ts files and one line appended to 40 tracked .ts files. One devReplay thread in the project.
  • 5 Diff panel loads: 36 single-file requests for tracked files.
span inside one tracked-file request median (range), n=36 starts at
GitVcsDriver.review.listUntracked (ls-files --others -- <path>) 293 ms (155-503) +12 ms
getReviewDiffPreview.stat 307 ms +345 ms
getReviewDiffPreview.patch 231 ms +681 ms
whole request 899 ms (617-1,072)

Every tracked-file request ran exactly these 3 git commands (36/36), with the listing first and the other two waiting for it. The listing never returned the path, because the path is tracked.

How to measure it again

  1. Check out the commit, vp i, cd apps/web && vp build.
  2. Seed: git clone -q --local <t3code checkout> p1, git remote remove origin, git checkout -b feature-1, commit one change. Then in PowerShell:
foreach ($d in 0..7) { $dir = "p1\untracked$d"; New-Item -ItemType Directory -Force $dir | Out-Null
  foreach ($f in 0..49) { Set-Content "$dir\f$f.ts" ("export const v$f = " + $f + ";`n" * 20) } }
Get-ChildItem "p1\apps\server\src" -Recurse -Filter *.ts | Select-Object -First 40 | ForEach-Object { Add-Content $_.FullName "`n// perf" }
  1. From apps/server, add the project and a thread: start T3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir <home> --port 4800 --host 127.0.0.1 --dev-url http://localhost:5733. Run node src/bin.ts project add <p1> --base-dir <home> and node src/bin.ts thread start --base-dir <home> --provider devReplay --model todo-list --wait <projectId> "task 1-0". Then restart without --dev-url, so it serves the production build.
  2. node src/bin.ts pair --ttl 1h --base-dir <home>, set the URL's host to 127.0.0.1:4800. Run the diff.cjs driver from Scrolling a large diff on Windows runs 6 git commands per file, and 3 of them re-resolve the branch, base and merge base the preview just resolved (about 1,650 git processes to view 272 files) #40182 with 5 loads and thread text 1-0. Copy <home>/userdata/logs/server.trace.ndjson* right away, then run:
// perfile.cjs <trace...>: review.getDiffPreview requests with exactly 3 git: each git's operation, start offset and duration, and medians
const fs = require("fs"); const sp = new Map();
for (const f of process.argv.slice(2)) for (const l of fs.readFileSync(f, "utf8").split("\n")) { try { const r = JSON.parse(l); if (r.type === "effect-span") sp.set(r.spanId, r); } catch {} }
const st = (s) => Number(BigInt(s.startTimeUnixNano) / 1000000n); const kids = new Map();
for (const s of sp.values()) { const k = kids.get(s.parentSpanId) || []; k.push(s); kids.set(s.parentSpanId, k); }
const desc = (s) => { const o = [], q = [s]; while (q.length) { const x = q.pop(); for (const c of kids.get(x.spanId) || []) { o.push(c); q.push(c); } } return o; };
const med = (a) => [...a].sort((x, y) => x - y)[a.length >> 1]; const per = {}; const tot = [];
for (const r of [...sp.values()].filter((s) => s.name === "ws.rpc.review.getDiffPreview")) {
  const g = desc(r).filter((x) => x.name === "runGitCommand"); if (g.length !== 3) continue; tot.push(Math.round(r.durationMs));
  for (const x of g) { const k = sp.get(x.parentSpanId).name; (per[k] = per[k] || []).push([st(x) - st(r), Math.round(x.durationMs)]); } }
console.log("requests", tot.length, "median", med(tot), "min", Math.min(...tot), "max", Math.max(...tot));
for (const [k, v] of Object.entries(per)) console.log(k, "starts at +" + med(v.map((x) => x[0])), "median", med(v.map((x) => x[1])), "ms");

Where the time goes

apps/server/src/vcs/GitVcsDriverCore.ts, prepareUntrackedReviewIndexOrReason (span prepareUntrackedReviewIndex). It always runs ls-files --others --exclude-standard -z -- <path> (operation GitVcsDriver.review.listUntracked) before the single-file diff, whatever the file's status. For a tracked path the result is empty, and the function returns { env: undefined }. Only then do getReviewDiffPreview.stat and getReviewDiffPreview.patch start.

Why it is avoidable

A path that is tracked, and listed as modified in the preview the patch belongs to, cannot be untracked. So for these requests the listing always answers "no" and only delays the diff. Open #40268 rewrites this listing for untracked files and leaves tracked files at 3 git, so it does not cover this.

What a fix has to show

The same 5 Diff panel loads, before and after, on the same seed:

  • A single-file request for a tracked, modified file runs 2 git instead of 3, and GitVcsDriver.review.listUntracked no longer appears in it.
  • The tracked-file request median drops by about the listing time: under 650 ms, from 899 ms.

What stays:

  • diff --stat and diff for the file (~0.5 s together under 4 concurrent requests);
  • the listing for files that are untracked, or whose status is not known;
  • intent-to-add files and renames whose previous path is tracked, which must still be found.

Found by the automated Windows performance sweep on 0fd4822.


Found by the automated Windows performance sweep on 0fd4822.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions