Skip to content

Each 30-s remote status poll starts 15-17 git processes per open thread on Windows, and 5-6 of them re-read HEAD, the upstream and the remote list that the same poll already read #40051

Closed

Description

@juliusmarminge

What is slow

With one thread open and the app idle, the server re-reads git status every 30 s. The remote half of that poll (VcsStatusBroadcaster.readRemoteStatus) starts 15 git processes per poll in a repository with no remote, and 17 in one with a GitHub origin. Nobody waits on it, but on Windows every git process costs 50–65 ms and a console host, and it runs for every open thread for as long as the app stays open. Five or six of those processes per poll re-read HEAD, the upstream and the remote list that the same poll has already read.

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on, Git 2.56.1.windows.1, Node 26. Commit 285558eb10.
  • Seed: 6 clones of this repository (about 32k files). 3 have origin = GitHub with main tracking origin/main, and 3 have no remote. Each has a local feature-<i> branch with one commit and no upstream. 3 devReplay threads per project.
  • Production web build. One headless Chromium page with one thread open, then 95 s idle (3 polls). One run in a no-remote repo and one in a GitHub-origin repo. Counts were the same on every poll.
repo all git in 95 s readRemoteStatus git per poll span time per poll
no remote 93 (4.8 s of git process time) 15 ~540 ms
GitHub origin 97 (6.3 s) 17 (incl. ~2.7 from lookupStatusPr) ~615 ms

Linux comparison, same seed and same commit: 15 per poll in the no-remote repo and 14 in the origin repo. The count is the same; on Linux each git process costs ~5 ms, against 50–65 ms on Windows.

Where the time goes

Per poll, from the server trace (runGitCommand spans under VcsStatusBroadcaster.readRemoteStatus, grouped by parent span), no-remote repo:

count span chain needed?
2 GitWorkflowService.currentBranch (before and after the read) yes: the branch-switch guard in VcsStatusBroadcaster.readRemoteStatus
1 GitVcsDriver.computeAheadCountAgainstBase (rev-list --count) yes: the answer
6 resolveBaseBranchForNoUpstream (3× readConfigValue, remoteExists, listRemoteNames, branchExists) out of scope: the base-branch lookup is the cause in #39984
1 refreshStatusUpstreamIfStale.headRef (symbolic-ref HEAD) re-reads HEAD
1 refreshStatusUpstreamIfStale.upstreamRemote (for-each-ref %(upstream:remotename)) re-reads the upstream
1 statusDetailsRemote.branch (rev-parse --symbolic-full-name HEAD) re-reads HEAD
1 readCurrentUpstreamRef → resolveCurrentUpstream (rev-parse @{upstream}) re-reads the upstream
2 resolvePrimaryDefaultBranchName (listRemoteNames, resolveDefaultBranchName) lists remotes a second time per poll

In the origin repo the same chain runs, and resolveDefaultBranchName (rev-parse refs/remotes/origin/HEAD) runs twice per poll: once in resolvePrimaryDefaultBranchName and once inside the base lookup.

Files: apps/server/src/vcs/VcsStatusBroadcaster.ts (readRemoteStatus), apps/server/src/git/GitManager.ts (readRemoteStatus), and apps/server/src/vcs/GitVcsDriverCore.ts (statusDetailsRemote, refreshStatusUpstreamIfStale, readStatusDetailsRemote, resolvePrimaryDefaultBranchName).

Why it is avoidable

In one poll, HEAD is read four times (currentBranch, headRef, statusDetailsRemote.branch and the after-guard), the upstream twice, and the remote list or the origin default branch twice. Nothing changes between those reads except through the branch switch that the after-guard already detects.

What a fix has to show

The same 95 s idle measurement before and after. Expected result, with the base-branch lookup (#39984) left as it is: readRemoteStatus starts at most 10 git per poll in the no-remote repo (from 15) and at most 12 in the origin repo (from 17). The guard reads (2) and the rev-list --count (1) cannot go away. The base-branch lookup's 6 are counted in #39984, not here. The status values the client receives must not change, and a branch switch during a poll must still be detected.

How to measure it again

  1. Check out the commit, run vp i, then cd apps/web && vp build.
  2. Make two repos: git clone --local <this repo> p0 and p1. In p0, git remote set-url origin https://github.com/pingdotgg/t3code.git, git fetch origin main and git branch -u origin/main main. In p1, git remote remove origin. In both, git checkout -B feature-x, then commit one file.
  3. Seed: from apps/server, start T3CODE_DEV_SEED=0 node --require spawnlog.cjs src/bin.ts serve --base-dir H --port 4800 --host 127.0.0.1 --dev-url http://localhost:5733 (this registers devReplay). Then, for each repo, run node src/bin.ts project add <repo> --base-dir H and node src/bin.ts thread start --base-dir H --provider devReplay --model todo-list --wait --json <projectId> "task".
  4. Stop the server and start it again without --dev-url, with SPAWNLOG=spawn.ndjson. Mint a link with node src/bin.ts pair --ttl 1h --base-dir H and rewrite its host to 127.0.0.1:4800.
  5. Run node idle.cjs <path to node_modules/.pnpm/playwright@*/node_modules/playwright> <pairUrl> <rowIndex> 95 marks.json. Then run node tracecount.cjs H/userdata/logs/server.trace.ndjson <idleFrom> <idleTo> '^VcsStatusBroadcaster.readRemoteStatus$' with OPS=1, and divide by 3. The sidebar rows show the project name, so pick the row index from marks.rows.
// spawnlog.cjs: node --require ./spawnlog.cjs ... (SPAWNLOG=<file>); logs every child with its start epoch and duration
const cp = require('child_process'); const fs = require('fs'); const out = process.env.SPAWNLOG || 'spawn.ndjson';
const log = (o) => { try { fs.appendFileSync(out, JSON.stringify(o) + '\n'); } catch {} };
for (const name of ['spawn', 'execFile', 'exec', 'fork']) { const orig = cp[name]; cp[name] = function (...a) { const t0 = Date.now(); const c = orig.apply(this, a);
  c.once && c.once('exit', (code) => log({ k: name, cmd: String(a[0]), args: Array.isArray(a[1]) ? a[1].map(String) : [], at: t0, ms: Date.now() - t0, code })); return c; }; }
require('module').syncBuiltinESMExports();
// idle.cjs <playwrightDir> <pairUrl> <rowIdx> <idleSeconds> <out.json>
const [pwDir, url, row, idleS, out] = process.argv.slice(2); const { chromium } = require(pwDir);
(async () => { const b = await chromium.launch(); const page = await (await b.newContext({ viewport: { width: 1600, height: 1000 } })).newPage(); const m = { start: Date.now() };
  await page.goto(url); await page.waitForSelector('[data-thread-item]', { timeout: 60000 }); await page.waitForTimeout(8000);
  const rows = page.locator('[data-thread-item]'); m.rows = []; for (let i = 0; i < await rows.count(); i++) m.rows.push((await rows.nth(i).innerText()).slice(0, 60));
  await rows.nth(+row).click(); m.clicked = Date.now(); await page.waitForTimeout(15000); m.idleFrom = Date.now(); await page.waitForTimeout(+idleS * 1000); m.idleTo = Date.now();
  require('fs').writeFileSync(out, JSON.stringify(m, null, 1)); await b.close(); })();
// tracecount.cjs <trace.ndjson[,more]> <fromMs> <toMs> <spanNameRegex>; OPS=1 prints the parent chain of each git command
const fs = require('fs'); const [files, from, to, re] = process.argv.slice(2); const S = new Map(), K = new Map();
for (const f of files.split(',')) for (const l of fs.readFileSync(f, 'utf8').split('\n')) { let s; try { s = JSON.parse(l); } catch { continue; } S.set(s.spanId, s); if (s.parentSpanId) (K.get(s.parentSpanId) || K.set(s.parentSpanId, []).get(s.parentSpanId)).push(s.spanId); }
const t = s => Number(BigInt(s.startTimeUnixNano) / 1000000n); const desc = (id, a = []) => { for (const k of K.get(id) || []) { a.push(S.get(k)); desc(k, a); } return a; };
const rx = new RegExp(re), agg = new Map();
for (const s of S.values()) { if (!rx.test(s.name) || t(s) < +from || t(s) > +to) continue; const g = desc(s.spanId).filter(x => x.name === 'runGitCommand');
  const e = agg.get(s.name) || { n: 0, git: 0, ops: new Map() }; e.n++; e.git += g.length;
  for (const x of g) { let a = S.get(x.parentSpanId), c = []; while (a && a.spanId !== s.spanId && c.length < 4) { c.push(a.name); a = S.get(a.parentSpanId); } const k = c.join(' < '); e.ops.set(k, (e.ops.get(k) || 0) + 1); } agg.set(s.name, e); }
for (const [k, e] of agg) { console.log(`${k}: n=${e.n} git=${e.git}`); if (process.env.OPS) for (const [o, c] of e.ops) console.log('  ', c, o); }

The local half of the same poll is a separate cause, handled by #40021 (local status re-read on unchanged polls). It is not counted here.


Found by the automated Windows performance sweep on 285558e.

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