Skip to content

Opening the branch picker on Windows reloads the branch list every time: 2 listRefs requests and 6 git per open even when no ref moved #40431

Closed

Description

@juliusmarminge

What is slow

Every time the branch picker in the thread toolbar opens, the client sends a local-only vcs.refreshStatus and then reloads the branch list with refresh: true, whatever the refresh found. That is two vcs.listRefs requests (6 git, about 190 ms of server work) and a cleared persisted branch cache for the whole environment, on every open, even when no ref has moved. #40385 already stopped this reload for the Git actions menu by comparing a refs digest. The picker uses its own command, refreshLocalStatusForPicker, which still invalidates refs unconditionally.

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on, Git 2.56.1.windows.1, commit 7d3677f.
  • A 32,168-file clone with a local bare remote, on branch work with 5 local and 5 remote branches. 113 replay threads in two projects. Headless Chromium on the thread page. Nothing changed in the repository between opens.
  • 7 picker opens (open, wait 4 s, Escape, wait 3 s). 7 of 7 sent the same requests:
+58   vcs.refreshStatus {"cwd":"C:\\p\\repos\\p0","localOnly":true}
+1105 vcs.listRefs {"cwd":"C:\\p\\repos\\p0","query":"work","refresh":true,"limit":10}
+1105 vcs.listRefs {"cwd":"C:\\p\\repos\\p0","refresh":true,"limit":100}
  • Git per open, from the server trace: ws.rpc.vcs.refreshStatus 10 git (886-1167 ms, median 1009 ms), ws.rpc.vcs.listRefs 6 git (177-209 ms, median 196 ms). 16 git per open in 6 of 7 runs. In the other run a background poll landed in the window and the refresh ran 16.
  • The picker list showed in 124-361 ms (median 145 ms) from the cached list, so the reload only replaces a list that was already right.

How to measure it again

Harness (Windows, PowerShell; the next agent starts from a fresh machine)

  1. Check out the commit in C:/p/wt. Run vp i, then vp build in apps/web.
  2. Make two large repositories with a remote: git clone --bare --no-local <a t3code checkout> C:/p/repos/remote.git, then for p0 and p1: git clone C:/p/repos/remote.git C:/p/repos/pN, set user.name/user.email, git checkout -b work; git push -u origin work, and git branch feat-a HEAD~20; git push -u origin feat-a (same for feat-b, feat-c). Each has about 32,000 files.
  3. Before the first server start, write C:/p/home/userdata/settings.json: {"providerInstances":{"devReplay":{"displayName":"Replay (dev)","driver":"acpRegistry","config":{"source":"local","commandPath":"<output of node -p process.execPath>","commandArgs":["C:/p/wt/apps/server/scripts/dev-replay-agent.ts"]}}}}
  4. In apps/server, with T3CODE_DEV_SEED=0, run node src/bin.ts serve --base-dir C:/p/home --port 4800 --host 127.0.0.1 and keep it running (over SSH, start it with Invoke-CimMethod Win32_Process Create; it listens after about 50 s).
  5. node src/bin.ts project add C:/p/repos/p0 --base-dir C:/p/home (and p1).
  6. Seed threads: from inside the repository, 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 prints a thread id mcp:<uuid>. This run seeded 113 threads (73 in p0, 40 in p1). Wait until the server is idle before measuring. The page path is /ENVID/mcp:<uuid>; common.cjs fills in userdata/environment-id.
  7. Pair: node src/bin.ts pair --ttl 1h --base-dir C:/p/home prints a URL ending in pair#token=...; replace its host with 127.0.0.1:4800 and export it as PAIR. Export PW as the checkout's node_modules/.pnpm/playwright@*/node_modules/playwright directory.
  8. Delete C:/p/home/userdata/logs/server.trace.ndjson* before a run; afterwards copy them to a directory and run sum.cjs over it. Each git process is a runGitCommand or VcsProcess.spawn span.

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>; CALLERS=1 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) : '');
}

picker.cjs (node picker.cjs /ENVID/<thread id> with RUNS=7 SEQ=1 TAG=picker), then node sum.cjs <traces> C:/p/perf/out/picker.jsonl:

const { open, record, reqs, seq } = require('./common.cjs');
(async () => {
  const runs = +(process.env.RUNS || 7); 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(10000);
  for (let i = 0; i < runs; i++) {
    const t0 = Date.now();
    await trigger.click();
    await page.getByRole('option').first().waitFor({ timeout: 30000 });
    const t1 = Date.now();
    await page.waitForTimeout(4000);
    await page.keyboard.press('Escape');
    await page.waitForTimeout(3000);
    const t2 = Date.now();
    const r = { run: i, start: t0, end: t2, shown: t1 - t0, reqs: reqs(sent, t0, t2) };
    if (process.env.SEQ) r.seq = seq(sent, t0, t2);
    record(tag, r); console.log(JSON.stringify(r));
  }
  await browser.close();
})();

Where the time goes

  • apps/web/src/components/BranchToolbarBranchSelector.tsx, handleOpenChange (line 683): on every open, it calls refreshLocalStatusForPicker({ cwd, localOnly: true }).
  • packages/client-runtime/src/state/vcs.ts, refreshLocalStatusForPicker (line 353): onSettled: invalidateRefs, which calls invalidateCachedVcsRefs. That clears the persisted refs cache for the environment (cache.clearVcsRefs(environmentId)) and bumps the refs revision, so both mounted listRefs queries refetch with refresh: true.
  • refreshStatus above it (line 339) uses invalidateCachedVcsRefsIfChanged with the server's refsDigest instead (perf(client-runtime): Git menu status refresh keeps the branch list when no ref moved #40385). The server returns no digest for localOnly refreshes: VcsStatusBroadcaster.refreshStatus skips readRefSnapshot when options.localOnly is set.

Why it is avoidable

The branch list can only be stale if a ref moved. The refs-digest check that already runs for the Git menu answers that with one for-each-ref read. The picker open throws away a correct list and reads it again, every time.

What a fix has to show

The same 7 picker opens on an unchanged repository, on Windows:

  • Expected: no vcs.listRefs request on an open when no ref moved since the last refresh, so 10-11 git per open instead of 16 (6 fewer listRefs git; a digest read may add 1). The persisted branch cache survives the open.
  • What stays: the local-only status refresh itself (10 git, about 1 s here), which this issue does not question.
  • Not regressed: a branch created, deleted or moved outside T3 Code (for example git branch new-x in a terminal) appears in the list on the next picker open.

Found by the automated Windows performance sweep on 7d3677f.


Found by the automated Windows performance sweep on 7d3677f.

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