Repository navigation
Description
What is slow
A user clicks Pull (vcs.pull). GitVcsDriverCore.pullCurrentBranch runs readStatusDetailsLocal once before the pull and again after it. Each read runs the worktree-wide git status --porcelain=2 and git diff --numstat, plus computeAheadCountAgainstBase. From the first read the function uses only branch and hasUpstream. From the second it uses only upstreamRef, for the result. The user waits for both reads before the pull answers. The status broadcast that follows (refreshGitStatus, 38 git) then reads everything again for the UI.
Measured
- Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on. Commit
c1464d6774, server from source serving the production web build. - Seed:
git clone --localof this repository (32,168 tracked files) asp0, and a second clonep1, both withoriginset to a local bare clone and on branchworktrackingorigin/work. Before each runp1pushes 3 new commits, sop0is 3 behind. - 6 runs per scenario over the app's own WebSocket from a paired page. Git counts are
runGitCommandspans in the server trace.
| scenario | click to result, median (range) | git in pullCurrentBranch |
|---|---|---|
| 3 commits behind | 1,864 ms (1,852-1,936) | 22 |
| already up to date | 1,517 ms (1,493-1,595) | 22 |
Span tree of one pull (behind):
1819ms git=22 pullCurrentBranch
+2 463ms git=6 readStatusDetailsLocal (uses branch, hasUpstream)
+61 318ms statusDetails.status
+61 270ms statusDetails.numstat
+379 86ms git=2 computeAheadCountAgainstBase
+465 28ms git=1 readConfigValue branch.<b>.remote
+493 40ms git=1 pullCurrentBranch.beforeSha
+533 585ms git=1 pullCurrentBranch.pull (git pull --ff-only)
+1118 40ms git=1 pullCurrentBranch.afterSha
+1158 662ms git=12 readStatusDetailsLocal <- re-read, uses only upstreamRef
+1217 315ms statusDetails.status
+1218 272ms statusDetails.numstat
+1532 288ms git=8 computeAheadCountAgainstBase
+1850 2071ms git=38 VcsStatusBroadcaster.refreshStatus (broadcast after the answer)
The up-to-date pull has the same shape: reads 479 ms + ~660 ms around a 230 ms git pull.
How to measure it again
- Check out the commit,
vp i,cd apps/web && vp build. - Seed:
git clone -q --bare --local <t3code checkout> bare.git. Forp0andp1:git clone -q --local <t3code checkout> <p>, setuser.name/user.email,git remote set-url origin <abs>/bare.git,git fetch origin,git checkout -B work origin/main,git push -u origin work. - From
apps/server:T3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir <home> --port 4800 --host 127.0.0.1,node src/bin.ts project add <p0> --base-dir <home>,node src/bin.ts pair --ttl 1h --base-dir <home>. Set the pairing URL's host to127.0.0.1:4800. node pull.cjs <playwright dir> <pairUrl> <p0> <p1> 6 out.json, then the same withUPTODATE=1. The Playwright dir isnode_modules/.pnpm/playwright@*/node_modules/playwright.- Copy
<home>/userdata/logs/server.trace.ndjson*, thennode sum.cjs ws.rpc.vcs.pull readStatusDetailsLocal,GitVcsDriver.pullCurrentBranch.pull <traces>(thesum.cjsfrom the thread-delete worktree issue of the same sweep: per root span, duration, git total and per named descendant count/ms/git). Note thatreadStatusDetailsLocal=3xthere includes the broadcast's read.
// pull.cjs <playwrightDir> <pairUrl> <repoDir> <upstreamPeerDir> <runs> <out.json>
// Each run: peer commits+pushes 3 commits (UPTODATE=1 skips), then the page sends vcs.pull for repoDir.
const [pw, pairUrl, repo, peer, runs, out] = process.argv.slice(2);
const { chromium } = require(pw); const fs = require("fs"); const path = require("path"); const cp = require("child_process");
const g = (d, ...a) => cp.execFileSync("git", ["-C", d, ...a], { stdio: ["ignore", "pipe", "ignore"] }).toString();
(async () => {
const b = await chromium.launch(); const p = await (await b.newContext()).newPage();
await p.addInitScript(() => { const O = window.WebSocket; window.__ws = []; window.WebSocket = class extends O { constructor(...a) { super(...a); if (String(a[0]).includes("/ws")) window.__ws.push(this); } }; });
await p.goto(pairUrl); await p.waitForTimeout(10000); const res = [];
for (let i = 0; i < +runs; i++) {
if (!process.env.UPTODATE) {
g(peer, "pull", "-q", "--ff-only");
for (let k = 0; k < 3; k++) { fs.appendFileSync(path.join(peer, "apps", "server", `pull-${k}.txt`), `pull ${i} ${k} ${Date.now()}\n`); g(peer, "add", "-A"); g(peer, "commit", "-qm", `peer ${i} ${k}`); }
g(peer, "push", "-q");
}
await p.waitForTimeout(5000);
const r = await p.evaluate(async ({ cwd, i }) => {
const ws = window.__ws.filter((w) => w.readyState === 1).at(-1); const id = String(800000000 + i);
return await new Promise((resolve) => { const t0 = performance.now();
const on = (ev) => { let ms; try { ms = [].concat(JSON.parse(ev.data)); } catch { return; }
for (const m of ms) { if (String(m.requestId) !== id) continue;
if (m._tag === "Exit") { ws.removeEventListener("message", on); resolve({ ms: Math.round(performance.now() - t0), exit: m.exit._tag, v: JSON.stringify(m.exit.value ?? m.exit.cause).slice(0, 200) }); } } };
ws.addEventListener("message", on);
ws.send(JSON.stringify({ _tag: "Request", id, tag: "vcs.pull", payload: { cwd }, headers: [] })); });
}, { cwd: repo, i });
r.run = i; console.log(JSON.stringify(r)); res.push(r); await p.waitForTimeout(7000);
}
fs.writeFileSync(out, JSON.stringify(res)); await b.close();
})();Where the time goes
apps/server/src/vcs/GitVcsDriverCore.ts, pullCurrentBranch:
- starts with
const details = yield* readStatusDetailsLocal(cwd)and reads onlydetails.branchanddetails.hasUpstream; - ends with
const refreshed = yield* readStatusDetailsLocal(cwd)and reads onlyrefreshed.upstreamRef.
Each readStatusDetailsLocal runs git status (315-330 ms), git diff --numstat (270 ms, in parallel) and computeAheadCountAgainstBase (2-8 git, 86-288 ms).
Why it is avoidable
git pull --ff-only does not change the branch's upstream configuration, so the upstream name read after the pull is the one known before it. Neither read uses the file list, line counts or ahead-of-base count that make it expensive. The status the UI shows is re-read by the broadcast after the answer anyway.
What a fix has to show
The same 6-run measurements, before and after, on the same seed:
- git in
pullCurrentBranchfrom 22 to at most 10; - 3 behind: click to result under 1.3 s, from 1.86 s;
- up to date: under 1.0 s, from 1.52 s.
What stays:
git pull --ff-only(230-600 ms);- the before/after
rev-parse HEADthat decidespulledversusskipped_up_to_date(~80 ms); - reading the branch and whether it has an upstream before pulling (detached HEAD and no-upstream errors must stay);
- the claim on a queued status fetch;
- the status broadcast after the answer (38 git), which updates every client.
Push has the same pattern for a different function (#40278, pushCurrentBranch/buildCompletionToast); this is the separate vcs.pull path.
Found by the automated Windows performance sweep on c1464d6.
Found by the automated Windows performance sweep on c1464d6.
Activity