Repository navigation
Description
What is slow
The Changes totals (thread details panel and Diff panel, review.getDiffPreview with metadataOnly: true and sourceKind: "branch-range") load in two stages. First a trackedOnly: true request returns totals for tracked files quickly. Then a second request returns the complete preview, including untracked files. On the server the second request starts from scratch. It resolves the branch, the base and the merge base again, and runs the same tracked diff stat over every changed file again, before adding the untracked listing. With 799 changed files on Windows the repeated stat takes as long as the first one, so the complete totals arrive about twice as late as the new work requires.
Measured
- Windows Server 2025, 4 vCPU, Defender on. Commit
80871270f9, server from source, production web build, headless Chromium. - Seed: 6 clones of this repository (~32k files each), 18 devReplay threads. In one project (no remote, branch
feature-3, no untracked files), 799 tracked.tsfiles modified. - Opening a thread in that project and opening and closing its Diff panel, 30 loads. Server trace over all of them:
| value | |
|---|---|
| tracked-only previews (9 git each) | 55 |
| …followed within 200 ms by a complete preview (10 git) | 53 |
| git commands in the complete preview that the tracked-only preview just ran | 9 of 10 |
| tracked-only request | median 1,019 ms (459–2,604) |
| complete request | median 1,395 ms (839–2,995) |
tracked diff stat (getReviewDiffPreview.stat), tracked-only stage |
median 1,420 ms (314–2,826) |
| the same stat again, complete stage | median 1,412 ms (317–3,016) |
untracked listing (review.listUntracked), the only new work |
median 435 ms (383–800) |
branch + merge base again (review.currentBranch, resolveReviewMergeBase) |
median 85 ms |
base-branch lookup again (resolveBaseBranchForNoUpstream; #40125's) |
median 223 ms |
(The stat medians are summed per request across the parallel dirty/base stats, so they can exceed the request time.)
How to measure it again
Setup as in the steps below, then run the driver and the trace script.
- Check out the commit,
vp i,cd apps/web && vp build. - Make a clone of this repository with
git clone --local <a t3code checkout> p3,git remote remove origin,git checkout -b feature-3, and commit one new file. Then modify 800 tracked TypeScript files (PowerShell):$f = git -C p3 ls-files -- '*.ts' | Select -First 800; foreach($x in $f){ Add-Content -LiteralPath (Join-Path p3 $x) -Value '// edit' }. - From
apps/server: startT3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir <home> --port 4800 --host 127.0.0.1 --dev-url http://localhost:5733, thennode src/bin.ts project add <p3> --base-dir <home>andnode src/bin.ts thread start --base-dir <home> --provider devReplay --model todo-list --wait --json <projectId> "task 3-0". Restart the server without--dev-url. - Pair (
node src/bin.ts pair --ttl 1h --base-dir <home>, host set to127.0.0.1:4800) and open the thread in Chromium, or open the Diff panel (Ctrl+D) a few times. Any client that opens the thread works. The driverdiff.cjsfrom the per-file patch issue of the same sweep does it 12 times. - Copy
<home>/userdata/logs/server.trace.ndjson*and run:
// pairs.cjs <trace.ndjson>...: tracked-only preview (9 git) followed by the complete preview (10 git), and the time each spends in the same steps
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 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 st = (s) => Number(BigInt(s.startTimeUnixNano) / 1000000n); const en = (s) => st(s) + s.durationMs;
const top = [...sp.values()].filter((s) => s.name === "ws.rpc.review.getDiffPreview").sort((a, b) => st(a) - st(b)).map((s) => ({ s, d: desc(s) })).map((o) => ({ ...o, git: o.d.filter((x) => x.name === "runGitCommand").length }));
const sum = (d, n) => Math.round(d.filter((x) => x.name === n).reduce((t, x) => t + x.durationMs, 0));
for (const a of top.filter((o) => o.git === 9)) { const b = top.find((o) => o.git === 10 && st(o.s) >= en(a.s) - 5 && st(o.s) - en(a.s) < 200); if (!b) continue;
console.log(JSON.stringify({ trackedMs: Math.round(a.s.durationMs), completeMs: Math.round(b.s.durationMs), statTracked: sum(a.d, "GitVcsDriver.getReviewDiffPreview.stat"), statComplete: sum(b.d, "GitVcsDriver.getReviewDiffPreview.stat"), untracked: sum(b.d, "GitVcsDriver.review.listUntracked") })); }Where the time goes
- Client:
packages/client-runtime/src/state/review.ts, thediffPreviewquery's execute. When there is no complete preview yet, it first requests{ ...input, trackedOnly: true }, emits that, and then requestsinputagain in full. Two independent RPCs. - Server:
apps/server/src/vcs/GitVcsDriverCore.ts,getReviewDiffPreview. Both requests runresolveReviewRepository(review.currentBranch),resolveReviewMergeBase(base lookup plusmerge-base), andreadTrackedDiff→readStats(diff --find-renames … --raw --numstat -z <mergeBase> --) for the dirty and base refs. The complete request also runsprepareUntrackedReviewIndex(ls-files --others --exclude-standard). With no untracked files that returns no temporary index, so its stat is the same command on the same tree as the tracked-only stat.
Why it is avoidable
The complete preview differs from the tracked-only one only by the untracked files. Everything else (branch, base, merge base, the stat of every tracked change) was computed by the request that answered a few milliseconds earlier, and is computed again in full.
What a fix has to show
The same loads, before and after, on the same seed:
- The complete stage no longer re-runs the tracked diff stat: git per two-stage Changes load drops from 19 to at most 11, and the complete totals arrive about 1 s sooner (stat median 1.41 s today) when the tree has no untracked files.
- What stays: the tracked-only answer first (it is what makes the totals appear early), one untracked listing, and a stat for untracked files when there are some. Totals and file lists are unchanged, including with untracked, renamed and binary files.
- Not counted: the repeated base-branch lookup (
resolveBaseBranchForNoUpstream, 223 ms median, which perf(server): resolve a branch's base once while its refs and config are unchanged #40125 caches), and the cancel/resend of the same preview on thread switches (Every thread switch cancels the Changes diff preview and sends it again with identical input: same-project Changes totals arrive ~250 ms later, and cross-project switches throw away 650–830 ms of git status work on Windows #39985).
Found by the automated Windows performance sweep on 8087127.
Found by the automated Windows performance sweep on 8087127.
Activity