Skip to content

The git status refresh after every turn on Windows reads the branch's remote and the remote URL twice: 2 of 17 git and ~110 ms repeated per turn #40499

Closed

Description

@juliusmarminge

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: refreshLocalStatus 12 (readLocalStatus 6, of which resolveHostingProvider 2 in 110 ms; upstreamDivergence 6) + refreshPullRequestStatus 5 (currentBranch 2, lookupStatusPr 3, of which resolveLookupHeadContext 2 in 130 ms).
  • On every turn (6/6) the argv list has config --get branch.work.remote ×2 and config --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

  1. Check out the commit in C:/p/wt; vp i; vp build in apps/web.
  2. 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.
  3. Write C:/p/home/userdata/settings.json with 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]}).
  4. Start the server from apps/server with T3CODE_DEV_SEED=0 and GIT_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.
  5. 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. Afterwards node 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 under RunFinalizationService.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') and readRemoteUrlNullable(cwd, <remote>).
  • The PR lookup (lookupStatusPr → resolveLookupHeadContext → resolveBranchHeadContext) reads the same two values through readLookupConfigValue / readLookupRemoteUrl. Those share results only inside withPrLookupGitReads, 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, then refreshPullRequestStatus), 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), with branch.<b>.remote and remote.<r>.url read once each.
  • What stays: one read of each per refresh. A refresh that runs only local status (the branch picker's localOnly refresh) or only the PR lookup (the 30-s poll) keeps its single pair. The post-turn repository identity read (remote -v plus gh-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.

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