Repository navigation
Description
What is slow
After every turn the server refreshes the thread's git status (RunFinalizationService.refresh: local status, upstream divergence, PR status). In that refresh, git config --get branch.<branch>.remote and git config --get-all remote.origin.url each run twice:
- first in
readLocalStatus→resolveHostingProvider(2 git, ~110 ms); - then about 550 ms later in the PR lookup's
resolveLookupHeadContext(2 git, ~130 ms with its other work), with the same answers.
That is 2 extra git processes on every turn on Windows (each with a console host), and the Git panel's PR status lands later by the same amount.
Measured
- Windows Server 2025, 4 vCPU, 16 GB, Defender on, commit 194025e. 32k-file repository on a branch with an upstream, plus a worktree thread on a branch without one. Replay provider. Git argv recorded with
GIT_TRACE2_EVENT. - 6 turns in the main checkout: 34 git per turn (one cold first run at 46).
RunFinalizationService.refresh= 17 git:refreshLocalStatus12 (readLocalStatus6, of whichresolveHostingProvider2 in 110 ms;upstreamDivergence6) +refreshPullRequestStatus5 (currentBranch2,lookupStatusPr3, of whichresolveLookupHeadContext2 in 130 ms). - On every turn (6/6) the argv list has
config --get branch.work.remote×2 andconfig --get-all remote.origin.url×2:
+6019 config --get branch.work.remote (resolveHostingProvider)
+6078 config --get-all remote.origin.url (resolveHostingProvider)
... status, divergence, base branch ...
+6574 config --get branch.work.remote (resolveLookupHeadContext)
+6650 config --get-all remote.origin.url (resolveLookupHeadContext)
- 6 turns in a worktree thread (branch
perf-wt, no upstream): 37 git per turn, the same pair repeated on every turn (branch.perf-wt.remote×2,remote.origin.url×2).
How to measure it again
- Check out the commit in
C:/p/wt;vp i;vp buildinapps/web. git clone --bare --no-local <a t3code checkout> C:/p/repos/remote.git;git clone C:/p/repos/remote.git C:/p/repos/p0; set user.name and user.email;git checkout -b work; git push -u origin work.- Write
C:/p/home/userdata/settings.jsonwith the replay provider (providerInstances.devReplay,driver: acpRegistry,config: {source: local, commandPath: <node -p process.execPath>, commandArgs: [C:/p/wt/apps/server/scripts/dev-replay-agent.ts]}). - Start the server from
apps/serverwithT3CODE_DEV_SEED=0andGIT_TRACE2_EVENT=C:\p\perf\g2:node src/bin.ts serve --base-dir C:/p/home --port 4800 --host 127.0.0.1.node src/bin.ts project add C:/p/repos/p0 --base-dir C:/p/home. node src/bin.ts thread start --base-dir C:/p/home --provider devReplay --model command-output C:/p/repos/p0 go(from inside the repository), then run turns.ps1 with that id. Afterwardsnode g2.cjs C:/p/perf/g2 C:/p/perf/out/turn.jsonl(g2.cjs below) for argv per turn, and the server trace (userdata/logs/server.trace.ndjson*) for the span tree underRunFinalizationService.refresh.
turns.ps1:
param([string]$id, [int]$n = 6, [string]$repo = "C:\p\repos\p0")
Set-Location $repo
for ($i = 0; $i -lt $n; $i++) {
$t0 = [DateTimeOffset]::Now.ToUnixTimeMilliseconds()
node C:\p\wt\apps\server\src\bin.ts thread send --base-dir C:/p/home $id go --wait 2>&1 | Out-Null
Start-Sleep 12
$t1 = [DateTimeOffset]::Now.ToUnixTimeMilliseconds()
New-Item -ItemType Directory -Force C:\p\perf\out | Out-Null
"{""run"":$i,""start"":$t0,""end"":$t1}" | Add-Content C:\p\perf\out\turn.jsonl
}g2.cjs:
const fs = require('fs'); const path = require('path'); const NL = String.fromCharCode(10);
const [dir, outFile] = process.argv.slice(2); const procs = [];
for (const f of fs.readdirSync(dir)) for (const l of fs.readFileSync(path.join(dir, f), 'utf8').split(NL)) { if (!l.includes('"event":"start"')) continue; const j = JSON.parse(l); if (!j.sid.includes('/')) procs.push({ t: Date.parse(j.time), argv: j.argv.slice(1).join(' ') }); break; }
for (const l of fs.readFileSync(outFile, 'utf8').split(NL)) { if (!l) continue; const r = JSON.parse(l);
const w = procs.filter((p) => p.t >= r.start && p.t <= r.end); const c = {};
for (const p of w) c[p.argv.slice(0, 110)] = (c[p.argv.slice(0, 110)] || 0) + 1;
console.log('run', r.run, 'git=' + w.length); for (const [k, v] of Object.entries(c).sort((a, b) => b[1] - a[1])) console.log(' ', v, k); }Where the time goes
apps/server/src/git/GitManager.ts,readLocalStatus→resolveHostingProvider:readConfigValueNullable(cwd, 'branch.<b>.remote')andreadRemoteUrlNullable(cwd, <remote>).- The PR lookup (
lookupStatusPr→resolveLookupHeadContext→resolveBranchHeadContext) reads the same two values throughreadLookupConfigValue/readLookupRemoteUrl. Those share results only insidewithPrLookupGitReads, which wraps the PR lookup alone, so the local-status reads from the same refresh are not reused. - Both run inside one
RunFinalizationService.refresh(local status, then divergence, thenrefreshPullRequestStatus), about 550 ms apart.
Why it is avoidable
One refresh reads the same two config values twice with nothing in between that could change them, and the PR lookup already has a per-lookup cache for exactly these reads.
What a fix has to show
The same turns before and after, counted from the git trace:
RunFinalizationService.refresh: 15 git per turn on a branch with an upstream (from 17), withbranch.<b>.remoteandremote.<r>.urlread once each.- What stays: one read of each per refresh. A refresh that runs only local status (the branch picker's
localOnlyrefresh) or only the PR lookup (the 30-s poll) keeps its single pair. The post-turn repository identity read (remote -vplusgh-resolved) is deliberate and out of scope. - Not regressed: changing a branch's remote or the remote URL between two turns is picked up by the next refresh.
Found by the automated Windows performance sweep on 194025e.
Found by the automated Windows performance sweep on 194025e.
Activity