Repository navigation
Description
What is slow
A user switches branches in the thread's branch picker. When the switch completes, the live status reports the new branch. The client then sends its own vcs.refreshStatus with localOnly: true, which reads the whole working tree again, and reloads the branch list when that read settles.
On a 32,000-file repository that read takes 2.1-2.3 s on the server. It starts at the same moment as the post-checkout status reads the server already runs for the switch, and competes with them for CPU and disk.
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 of this repository with a local bare remote. Branch
worktracksorigin/work; branchesfeat-a,feat-bandfeat-csit 20 commits back. One thread (replay provider). Headless Chromium through Playwright. - 7 picker switches alternating
feat-aandwork, with the thread details panel open:- 6 of 7 switches sent one extra
vcs.refreshStatus(localOnly) 1.7-2.7 s after the click, as the switch finished. The first switch of the session did not. - Server time for that request: 2,075 / 2,293 / 2,306 / 2,257 / 2,290 / 2,192 ms (median 2,275 ms).
- Each ran 10 git: status, numstat, index path, base-branch stamp, merge base, branch change totals, 2 config reads, branchExists and remote URL.
- When it settled, it sent 2 more
vcs.listRefswith refresh (1 git each).
- 6 of 7 switches sent one extra
- Whole switch, measured over 8 s from the click: median 104 git (98-114) when the extra read fired, 79 when it did not.
- On a draft New thread page the branch selector is mounted twice (composer toolbar and details panel). There, 6 of 7 switches sent the request twice in the same millisecond, and the server folded the second into the first.
- Request order for one switch, in ms after the click:
+63 vcs.switchRef refName=work
+1907 vcs.refreshStatus localOnly=true
+1908 review.getDiffPreview
+1934 orchestration.dispatchCommand thread.metadata.update
+2011 vcs.listRefs refresh=true limit=10 / limit=100 (switchRef settled)
+4291 vcs.listRefs refresh=true limit=10 / limit=100 (the extra refresh settled)
How to measure it again
Harness (Windows, PowerShell)
- Check out the commit in
C:/p/wt. Runvp i, thenvp buildinapps/web. - Make a large repository with a remote:
git clone --bare --no-local <a t3code checkout> C:/p/repos/remote.gitgit -c core.longpaths=true clone C:/p/repos/remote.git C:/p/repos/p0- In p0: set user.name and user.email, then
git checkout -b work; git push -u origin work. - Add three branches 20 commits back:
git branch feat-a HEAD~20; git push -u origin feat-a, and the same for feat-b and feat-c. - The result has about 32,000 files.
- Add the free replay provider. Before the first server start, write
C:/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"]}}}} - In
apps/server, withT3CODE_DEV_SEED=0set, runnode src/bin.ts serve --base-dir C:/p/home --port 4800 --host 127.0.0.1and keep it running. Over SSH, start it withInvoke-CimMethod Win32_Process Create. node src/bin.ts project add C:/p/repos/p0 --base-dir C:/p/home- Create a thread. In C:/p/repos/p0, run
node C:/p/wt/apps/server/src/bin.ts thread start --base-dir C:/p/home --provider devReplay --model command-output C:/p/repos/p0 go.thread listwith the same base dir prints its id,mcp:<uuid>. The page path is/ENVID/mcp:<uuid>; common.cjs fills inuserdata/environment-id. - Pair a browser:
node src/bin.ts pair --ttl 1h --base-dir C:/p/homeprints a URL ending inpair#token=....- Replace its host with 127.0.0.1:4800 and export the URL as
PAIR. - Export
PWas the checkout'snode_modules/.pnpm/playwright@*/node_modules/playwrightdirectory.
- Delete
C:/p/home/userdata/logs/server.trace.ndjson*before each run. Afterwards, copy those files to a directory and run sum.cjs over it. Each git process appears in the trace as arunGitCommandorVcsProcess.spawnspan.
common.cjs:
const fs = require('fs');
const { chromium } = require(process.env.PW);
const NL = String.fromCharCode(10);
exports.open = async (path) => {
const browser = await chromium.launch();
const page = await (await browser.newContext({ viewport: { width: 1600, height: 1000 } })).newPage();
const sent = [];
page.on('websocket', (ws) => ws.on('framesent', (f) => {
try { for (const line of String(f.payload).split(NL)) { if (!line) continue; const j = JSON.parse(line); if (j._tag === 'Request') sent.push({ t: Date.now(), tag: j.tag, p: JSON.stringify(j.payload).slice(0, 160) }); } } catch {}
}));
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' + path.replace('ENVID', env));
return { browser, page, sent };
};
exports.record = (tag, rec) => { fs.mkdirSync('C:/p/perf/out', { recursive: true }); fs.appendFileSync('C:/p/perf/out/' + tag + '.jsonl', JSON.stringify(rec) + NL); };
exports.reqs = (sent, a, b) => { const c = {}; for (const s of sent) if (s.t >= a && s.t <= b) c[s.tag] = (c[s.tag] || 0) + 1; return c; };
exports.seq = (sent, a, b) => sent.filter((s) => s.t >= a && s.t <= b && s.tag !== 'server.reportClientActivity').map((s) => '+' + (s.t - a) + ' ' + s.tag + ' ' + s.p);sum.cjs (node sum.cjs <traceDir> <out.jsonl> [startField] [endField]; CALLERS=1 also lists the calling span):
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, ms: new Set(), callers: {} }; e.n++; e.ms.add(Math.round(rt.durationMs)); const c = caller(sp); e.callers[c] = (e.callers[c] || 0) + 1; roots.set(rt.name, e); }
let total = 0; for (const e of roots.values()) total += e.n;
console.log('run', r.run, r.target || '', 'total git=' + total);
for (const [k, e] of roots) console.log(' ', k, 'git=' + e.n, 'ms=' + [...e.ms].join(','), process.env.CALLERS ? JSON.stringify(e.callers) : '');
}branch.cjs (node branch.cjs /ENVID/<thread id> with RUNS=7 SEQ=1 TAG=bt):
const { open, record, reqs, seq } = require('./common.cjs');
(async () => {
const runs = +(process.env.RUNS || 6); const tag = process.env.TAG;
const { browser, page, sent } = await open(process.argv[2]);
const trigger = page.getByRole('combobox', { name: /^Branch:/ }).first();
await trigger.waitFor({ timeout: 60000 });
await page.waitForTimeout(8000);
const targets = ['feat-a', 'work'];
for (let i = 0; i < runs; i++) {
const target = targets[i % 2];
const t0 = Date.now();
await trigger.click();
const opt = page.getByRole('option', { name: target }).first();
await opt.waitFor({ timeout: 30000 });
const t1 = Date.now();
await page.waitForTimeout(2500);
const t2 = Date.now();
await opt.click();
await page.waitForFunction((b) => { const el = [...document.querySelectorAll('[role=combobox]')].find((e) => (e.getAttribute('aria-label') || '').startsWith('Branch:')); return el && el.getAttribute('aria-label') === 'Branch: ' + b && !el.disabled; }, target, { timeout: 60000 });
const t3 = Date.now();
await page.waitForTimeout(6000);
const t4 = Date.now();
const rec = { run: i, target, openStart: t0, listShown: t1 - t0, pickStart: t2, switchMs: t3 - t2, end: t4, openReqs: reqs(sent, t0, t2 - 1), switchReqs: reqs(sent, t2, t4) };
record(tag, rec); console.log(JSON.stringify(rec)); if (process.env.SEQ) console.log(seq(sent, t2, t4).join(String.fromCharCode(10)));
}
await browser.close();
})().catch((e) => { console.error(e); process.exit(1); });Count the post-switch vcs.refreshStatus in switchReqs. Then node sum.cjs <traces> C:/p/perf/out/bt.jsonl pickStart end shows the ws.rpc.vcs.refreshStatus root (10 git) in each switch window.
Where the time goes
apps/web/src/components/BranchToolbarBranchSelector.tsx, the refreshRefsMissingStatusBranch effect (line 629). It calls refreshStaleRefs (refreshLocalStatusForPicker with localOnly) whenever branchStatusQuery.data.refName changes to a branch that the loaded refs list does not mark current. The comment above it says it exists for a checkout made outside T3 Code, such as a clone finishing.
After a switch made in this same picker:
- The server's
refreshAfterCheckoutpublishes the new branch beforevcs.switchRefreturns. - The refs list still marks the old branch current, so the effect fires.
switchRef's ownonSettled: invalidateRefsthen reloads the refs anyway.
Server side, the request runs VcsStatusBroadcaster.refreshStatus, then refreshLocalStatusCore: a full local status read of 10 git. Each mounted selector fires on its own, so the draft page sends two.
Why it is avoidable
This client made the switch through vcs.switchRef, whose settle already reloads the refs. The server's post-checkout refresh already reads and publishes the new local status. The extra read repeats that status read only to correct a refs list that is about to be reloaded anyway.
What a fix has to show
Same driver, 7 switches on the thread page:
- Expected: 0 client-sent
vcs.refreshStatusafter a switch made in the picker, down from 1 in 6 of 7 (2 on the draft page). That removes 10 git and a ~2.2 s server read from each switch, plus the 2vcs.listRefsits settle adds. Switch total about 92 git or fewer, from a median of 104. - What stays:
vcs.switchRef(4 git) and the server's post-checkout refresh (owned by perf(server): status subscribe and branch switch no longer read local Git status twice #38949). - Not regressed: a checkout made outside T3 Code (
git checkout feat-bin a terminal) still updates the picker's current branch.
Found by the automated Windows performance sweep on 989d7ec.
Activity