Repository navigation
Description
What is slow
With a thread open and the app idle, the server polls remote status every 30 s, starting with a background git fetch --dry-run. On Windows that dry run changes the modification time of .git/refs/remotes/<remote> even when no ref moves. The base-branch cache key includes that directory's stat, so every poll misses the cache and resolves the base branch again: 6 git and about 220-270 ms per poll, for as long as a thread is open.
User actions pay for it too. Any refresh that fetches first, such as opening the Git actions menu, misses the same cache. The menu opens that fetched ran 34 git; those that did not ran 26.
Measured
- Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on, Git 2.56.1.windows.1, commit 989d7ec.
- A 32,210-file clone with a local bare remote, on a branch with an upstream. No new commits on the remote at any point. One thread open in headless Chromium, idle for 180 s after a 15-s settle.
- 125 git in 180 s, all under
VcsStatusBroadcaster.retainRemotePoller: 6 polls of 19-21 git. - In every poll,
resolveBaseBranchForNoUpstream.cachedread the stamp (1 git), missed, and ran the uncached resolution: 6 git, 221-268 ms. Those 6 are readConfigValue for t3-merge-base-ref, readBranchBase (2 config reads), remoteExists, resolveDefaultBranchName and remoteBranchExists. - One poll:
readStatusDetailsRemote 815ms git=15
refreshStatusUpstreamIfStale 320ms git=3 (upstream remote, count-objects, fetch --dry-run 220ms)
upstream ref, divergence, primary default branch git=3
computeAheadCountAgainstBase 318ms git=8
resolveBaseBranchForNoUpstream.cached 268ms git=7
readBaseBranchInputsStamp git=1
resolveBaseBranchForNoUpstream 221ms git=6 <- cache miss every poll
rev-list --count git=1
- Direct check with stamp.cjs (below) on the same repository: after
status,count-objectsandrev-parse @{u}the stamp was unchanged. Afterfetch --dry-run, onlyrefs/remotes/originchanged (mtime 1795268937989 became 1795269026728). - The same
git fetch --dry-run --no-tags --no-auto-gc --no-write-fetch-head -- originon Linux (Git 2.43) leaves the directory's mtime unchanged.
How to measure it again
stamp.cjs (point repo at any clone with a remote) reproduces the cause in seconds:
const fs = require('fs'); const path = require('path'); const cp = require('child_process'); const crypto = require('crypto');
const repo = 'C:/p/repos/p0', gd = path.join(repo, '.git');
const tok = (t) => { try { const s = fs.statSync(t, { bigint: true }); return s.ino + ':' + s.size + ':' + Number(s.mtimeMs); } catch { return '-'; } };
const stamp = () => { const out = {}; out.config = crypto.createHash('sha256').update(cp.execFileSync('git', ['config', '--list', '-z'], { cwd: repo })).digest('hex').slice(0, 12);
for (const n of ['packed-refs', 'reftable/tables.list']) out[n] = tok(path.join(gd, n));
const dirs = [path.join(gd, 'refs', 'heads'), path.join(gd, 'refs', 'remotes')];
for (let i = 0; i < dirs.length; i++) { out[path.relative(gd, dirs[i])] = tok(dirs[i]); for (const e of fs.readdirSync(dirs[i], { withFileTypes: true })) if (e.isDirectory()) dirs.push(path.join(dirs[i], e.name)); }
return out; };
const diff = (a, b, label) => { const d = Object.keys({ ...a, ...b }).filter((k) => a[k] !== b[k]); console.log(label, d.length ? d.map((k) => k + ': ' + a[k] + ' -> ' + b[k]).join(' | ') : 'unchanged'); };
let s0 = stamp();
for (const [label, args] of [['status', ['status', '--porcelain=v2', '-z']], ['fetch dry-run', ['fetch', '--dry-run', '--no-tags', '--no-auto-gc', '--no-write-fetch-head', '--', 'origin']], ['count-objects', ['count-objects', '-v']]]) { cp.spawnSync('git', args, { cwd: repo }); const s1 = stamp(); diff(s0, s1, label); s0 = s1; }In-app count:
- Build the checkout (
vp i, thenvp buildin apps/web) and clone a large repo with a remote as above. Before the first start, write the replay provider intoC:/p/home/userdata/settings.json:{"providerInstances":{"devReplay":{"displayName":"Replay (dev)","driver":"acpRegistry","config":{"source":"local","commandPath":"<full path of node.exe>","commandArgs":["C:/p/wt/apps/server/scripts/dev-replay-agent.ts"]}}}} - Start
node src/bin.ts serve --base-dir C:/p/home --port 4800 --host 127.0.0.1with T3CODE_DEV_SEED=0, then runproject add. thread start --provider devReplay --model command-output <repo> gocreates a thread; the page path is/ENVID/mcp:<uuid>.- Pair with
node src/bin.ts pair --ttl 1h --base-dir C:/p/home(host 127.0.0.1:4800) and export it asPAIR. ExportPWas the checkout'snode_modules/.pnpm/playwright@*/node_modules/playwrightdirectory. - Clear
C:/p/home/userdata/logs/server.trace.ndjson*. - Run idle.cjs, then
CALLERS=1 node sum.cjs <traces> C:/p/perf/out/idle.jsonl. Per poll it shows resolveDefaultBranchName 2, remoteExists 1, remoteBranchExists 1 and readConfigValue about 3. A git process is arunGitCommandorVcsProcess.spawnspan.
idle.cjs (node idle.cjs /ENVID/<thread id> with TAG=idle):
const fs = require('fs');
const { chromium } = require(process.env.PW);
(async () => {
const browser = await chromium.launch();
const page = await (await browser.newContext()).newPage();
await page.goto(process.env.PAIR); await page.waitForTimeout(4000);
const env = fs.readFileSync('C:/p/home/userdata/environment-id', 'utf8').trim();
await page.goto('http://127.0.0.1:4800' + process.argv[2].replace('ENVID', env));
await page.getByRole('button', { name: 'Git action options' }).first().waitFor({ timeout: 60000 });
await page.waitForTimeout(15000);
const t0 = Date.now(); await page.waitForTimeout(180000); const t1 = Date.now();
fs.mkdirSync('C:/p/perf/out', { recursive: true });
fs.appendFileSync('C:/p/perf/out/' + process.env.TAG + '.jsonl', JSON.stringify({ run: 0, start: t0, end: t1 }) + String.fromCharCode(10));
await browser.close();
})();sum.cjs:
const fs = require('fs'); const path = require('path');
const NL = String.fromCharCode(10);
const [dir, outFile, sf = 'start', ef = 'end'] = process.argv.slice(2);
const spans = [];
for (const f of fs.readdirSync(dir)) for (const l of fs.readFileSync(path.join(dir, f), 'utf8').split(NL)) { if (!l) continue; try { spans.push(JSON.parse(l)); } catch {} }
const byId = new Map(spans.map((s) => [s.spanId, s]));
const ms = (s) => Number(BigInt(s.startTimeUnixNano) / 1000000n);
const plumbing = ['VcsProcess', 'runGitCommand', 'GitVcsDriver.execute', 'GitVcsDriver.run', 'GitVcsDriver.gitCommand', 'gitCommand', 'ProcessRunner'];
const root = (s) => { while (s.parentSpanId && byId.has(s.parentSpanId)) s = byId.get(s.parentSpanId); return s; };
const caller = (s) => { let p = s; while (p.parentSpanId && byId.has(p.parentSpanId)) { p = byId.get(p.parentSpanId); if (!plumbing.some((x) => p.name.startsWith(x))) return p.name; } return '?'; };
const spawns = spans.filter((s) => s.name === 'VcsProcess.spawn' || s.name === 'runGitCommand');
for (const l of fs.readFileSync(outFile, 'utf8').split(NL)) {
if (!l) continue; const r = JSON.parse(l); const a = r[sf], b = r[ef];
const roots = new Map();
for (const sp of spawns) { const t = ms(sp); if (t < a || t > b) continue; const rt = root(sp); const e = roots.get(rt.name) || { n: 0, callers: {} }; e.n++; const c = caller(sp); e.callers[c] = (e.callers[c] || 0) + 1; roots.set(rt.name, e); }
for (const [k, e] of roots) console.log(k, 'git=' + e.n, process.env.CALLERS ? JSON.stringify(e.callers) : '');
}Where the time goes
apps/server/src/vcs/GitVcsDriverCore.ts:
readBaseBranchInputsStamp(line 2412) stamps the base-branch cache with the ino:size:mtime ofrefs/heads,refs/remotesand every subdirectory, plus packed-refs, reftable/tables.list and a hash ofconfig --list.fetchRemoteForStatus(line 1511) runsfetch --dry-runon every poll. On Windows that updates the mtime ofrefs/remotes/<remote>without changing any ref.- So
resolveBaseBranchForNoUpstream(line 2477) gets a new key every poll and never reuses its cached result.
Why it is avoidable
The base branch depends only on ref values and config, and a dry-run fetch changes neither. The stamp relies on a directory timestamp that Git for Windows touches even when nothing changes. This repository chose that signal, so the miss on every poll is caused here, not by Git.
What a fix has to show
Same setup, 180 s idle with one thread open, on Windows:
- Expected: the uncached
resolveBaseBranchForNoUpstreamruns at most once in the window, not in all 6 polls. Polls drop to 13-15 git from 19-21, saving about 220 ms of git per poll (about 36 fewer git per 3 minutes per open thread). A Git menu open whose refresh fetched costs the same as one that did not (26 git). - What stays: the fetch (2 git), the stamp read (1 git) and the rest of the remote status read.
- Not regressed: a real ref change, such as a new remote commit fetched by the poll or
git remote set-head origin <other>, still changes the computed base branch on the next read.
Found by the automated Windows performance sweep on 989d7ec.
Activity