Skip to content

Opening the Diff panel fetches every visible file patch twice: 8 requests and 48 git processes for 4 files on each open (Windows, 11 of 11 opens) #40184

Closed

Description

@juliusmarminge

What is slow

When you open the Diff panel (Ctrl+D) on a thread whose Changes preview is already loaded, the panel requests the patches of the first 4 files at once. In the same moment it revalidates the preview (refreshOnShow). When the revalidated preview arrives about 2.4 s later, all 4 patches are requested again with identical payloads, and the server diffs the same files a second time. Each patch request is 6 git processes on the server.

Measured

  • Windows Server 2025, 4 vCPU, Defender on. Commit 80871270f9, server from source, production web build served by the server, headless Chromium through Playwright.
  • Seed: 6 clones of this repository (~32k files each), 18 devReplay threads; 799 tracked .ts files modified in one project.
  • Open the thread, make sure the panel is closed, wait, press Ctrl+D. n=11 opens:
per open
single-file review.getDiffPreview requests 8 (11/11 opens)
unique payloads among them 4
first batch sent +224–266 ms after Ctrl+D
preview revalidation (metadataOnly, 10 git) sent +224–266 ms
second, identical batch sent +2,612–2,842 ms (when the revalidation answers)
both batches answered (not interrupted) yes, 8/8
first file visible 332–382 ms (median 361)
long tasks from Ctrl+D 261–336 ms
  • An earlier run without closing the panel first: 6/6 opens, 8 requests for 4 files.
  • Server cost of the duplicate batch: 4 requests × 6 git = 24 git processes per open, ~1.1–1.4 s each, running in parallel with the revalidation.

How to measure it again

  1. Check out the commit, vp i, cd apps/web && vp build.
  2. 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' }.
  3. From apps/server: T3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir <home> --port 4800 --host 127.0.0.1 --dev-url http://localhost:5733, then node src/bin.ts project add <p3> --base-dir <home> and node 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.
  4. node src/bin.ts pair --ttl 1h --base-dir <home>; set the URL's host to 127.0.0.1:4800; use a new token per run.
  5. node diff.cjs <node_modules/.pnpm/playwright@*/node_modules/playwright> <pairUrl> 12 3-0 out.json, then summarize with the second script.
// diff.cjs <playwrightDir> <pairUrl> <loads> <threadText> <out.json>: open the thread, close the Diff panel if open, press Ctrl+D; record review.* requests (offset ms, id, payload, answer)
const [pw, pairUrl, loads, threadText, out] = process.argv.slice(2); const { chromium } = require(pw); const fs = require("node:fs");
(async () => { const b = await chromium.launch(); const ctx = await b.newContext({ viewport: { width: 1600, height: 1000 } }); const res = [];
  let p = await ctx.newPage(); await p.goto(pairUrl); await p.waitForTimeout(8000); const origin = new URL(pairUrl).origin; await p.close();
  for (let i = 0; i < +loads; i++) { p = await ctx.newPage(); let cur = null;
    p.on("websocket", (ws) => { ws.on("framesent", (f) => { if (!cur) return; let m; try { m = JSON.parse(String(f.payload)); } catch { return; }
        if (m.tag && /review\./.test(m.tag)) cur.reqs.push([Date.now() - cur.w0, m.id, m.tag, JSON.stringify(m.payload).slice(0, 400)]);
        if (m._tag === "Interrupt") cur.reqs.push([Date.now() - cur.w0, "INT", m.requestId]); });
      ws.on("framereceived", (f) => { if (!cur) return; const s = String(f.payload); if (!s.includes('"Exit"')) return; try { for (const x of [].concat(JSON.parse(s))) if (x._tag === "Exit") { const r = cur.reqs.find((q) => String(q[1]) === String(x.requestId)); if (r) r.push(Date.now() - cur.w0, x.exit?._tag); } } catch {} }); });
    await p.goto(origin + "/"); await p.waitForTimeout(6000);
    const c0 = Date.now(); cur = { load: i, reqs: [], w0: c0 };
    await p.locator("[data-thread-item]", { hasText: threadText }).first().click(); await p.waitForTimeout(5000);
    if (await p.locator("[data-diff-file-key]").count() > 0) { await p.keyboard.press("Control+d"); await p.waitForTimeout(3000); }
    cur.reqs.push([Date.now() - c0, "OPEN"]); await p.keyboard.press("Control+d"); await p.waitForTimeout(10000);
    res.push(cur); cur = null; await p.close(); }
  fs.writeFileSync(out, JSON.stringify(res)); await b.close(); })();
// opens.cjs <out.json>: per open, file patch requests after Ctrl+D, how many are unique, and when they were sent
const R = JSON.parse(require("fs").readFileSync(process.argv[2], "utf8"));
for (const r of R) { const open = r.reqs.find((q) => q[1] === "OPEN")[0];
  const fp = r.reqs.filter((q) => q[2] === "review.getDiffPreview" && q[3].includes('"file"') && q[0] >= open);
  const md = r.reqs.filter((q) => q[2] === "review.getDiffPreview" && !q[3].includes('"file"') && q[0] >= open);
  console.log(r.load, "patches", fp.length, "unique", new Set(fp.map((q) => q[3])).size, "at", fp.map((q) => q[0] - open).join(","), "| preview at", md.map((q) => q[0] - open).join(",")); }

Where the time goes

  • packages/client-runtime/src/state/review.ts: diffFilePatch has refreshTrigger: previewRevisionFamily(...), and previewRevisionFamily returns the preview's generatedAt. Any new preview revision therefore refreshes every patch read under the old one (comment: "a newer preview revision makes every patch read under the old one stale").
  • apps/web/src/components/DiffPanel.tsx: useLiveRefresh(..., { refreshOnShow: true }) revalidates the preview when the panel is shown. useReviewFilePatches (apps/web/src/components/diffs/useReviewFilePatches.ts) requests the first 4 patches from the cached preview in the same render.
  • So the first batch is sent 0–40 ms before or after the revalidation request, and is refreshed when that revalidation answers.

Why it is avoidable

The first batch reads the working tree at the same moment as the revalidation, so the revalidated preview cannot make those patches staler than they already are. Refreshing them repeats the same 4 diffs. Note that diffHash alone cannot decide whether a patch is stale: for metadata-only previews it hashes only the numstat, which misses same-line-count edits.

What a fix has to show

The same 11+ opens, before and after:

  • File patch requests per open drop from 8 to 4 (git processes from 48 to 24), and the second batch at +2.6–2.8 s disappears.
  • First file visible stays at or under today's ~360 ms (cached preview) and ~1 s (cold).
  • What stays: patches still refresh when the preview changed after they were read (a file edited outside T3 Code while the panel was hidden, or a new turn). Show that with a test where a file changes between the two previews.

Found by the automated Windows performance sweep on 8087127.


Found by the automated Windows performance sweep on 8087127.

Activity

  1. shivamhwp commented on Nov 21, 2026

    @shivamhwp
    Collaborator

    [Haiku 5.5][Claude Code] on behalf of shivam.

    Julius has taken this over in #40217, so this is what I found before the handoff. Nothing is pushed.

    • Reproduced on base 982bbcdfe13 in the web app: headless Chromium on a Linux VM, not the Windows machine from the report. Thread with 6 modified files, opened the Diff panel, counted review.getDiffPreview file requests. Result: 8 requests for 4 files, the same duplicate batch the report describes.
    • Tried a fix that refreshes a patch only if it was read before the newer preview revision was requested. Its unit test passes in runtime.test.ts (the duplicate case fails on the old code). In the web app the same scenario still gives 8 requests on the fixed head, so that fix does not remove the duplicate. I did not confirm the cause. My suspect is that the revision-to-request-time lookup depends on object identity through the answer path.
    • Not shown: the Windows setup from the report, and any server timing other than the one I ran.

    The scenario and proof output stay on my side, not uploaded.

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