Repository navigation
Description
What is slow
Every git command the server runs on Windows gets its own console host (conhost.exe) unless its exact form is on a short allowlist. At each server start with 6 projects, 38 of the 56–57 git processes the server launches start a console host. That is 38 extra processes per start, all for commands that only read config or refs. The same forms run again in status polls, thread switches and PR lookups, so the cost repeats all day.
Measured
- Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on. Commit
b568fcbaa6, server from source, Git for Windows (ucrt64). - Seed: 6 projects, each a ~32k-file clone of this repository. 3 have
originon GitHub and 3 have no remote; each is on afeature-<i>branch with one commit. 18 finished threads. - Process creation audited with Windows event 4688 over the first 45 s of 3 warm starts. The result was the same in all 3:
| per start | |
|---|---|
| git processes started by the server | 56–57 |
…of which started a conhost.exe |
38 (3/3 starts) |
…already console-free (remote, config --get branch.<b>.remote, config --get branch.<b>.merge) |
18–19 |
The 38, by form:
| form | count | spawn path |
|---|---|---|
git -C <root> rev-parse --show-toplevel |
6 | RepositoryIdentityResolver → ProcessRunner.run |
git -C <root> remote -v |
6 | same |
git -C <root> config --get-regexp ^remote\..*\.gh-resolved$ |
6 | same |
config --get-all remote.origin.url |
6 | GitVcsDriverCore |
rev-parse --verify --quiet --symbolic-full-name refs/remotes/origin/HEAD |
4 | GitVcsDriverCore |
for-each-ref --format=… refs/heads/<b> |
4 | GitVcsDriverCore |
for-each-ref --format=… refs/heads/<b> refs/remotes/origin/<b> |
2 | GitVcsDriverCore |
for-each-ref --format=… refs/remotes/origin/<b> |
2 | GitVcsDriverCore |
for-each-ref --count=1 --format=… refs/remotes |
2 | GitVcsDriverCore |
How to measure it again
Setup (Windows, fresh machine)
- Check out the commit, run
vp i, thencd apps/web && vp build. Install the provider CLIs:npm i -g @openai/codex @anthropic-ai/claude-code. Putnpm prefix -gon PATH for the server. - Seed 6 projects of ~32k files each:
git clone --local <a t3code checkout> p<i>for i = 0..5. For p0–p2, setorigintohttps://github.com/pingdotgg/t3code.git,git fetch origin mainandgit branch -u origin/main main. For p3–p5, rungit remote remove origin. In every repo, check outfeature-<i>and commit one file. - From
apps/server, start a seeding server:T3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir H --port 4800 --host 127.0.0.1 --dev-url http://localhost:5733. For each repo, runnode src/bin.ts project add <repo> --base-dir Hand then 3×node src/bin.ts thread start --base-dir H --provider devReplay --model todo-list --wait --json <projectId> "task". Stop the server. - Start the measured server without
--dev-url, with Defender real-time scanning on and no exclusion:T3CODE_DEV_SEED=0 SPAWNLOG=spawn.ndjson node --require ./spawnlog.cjs src/bin.ts serve --base-dir H --port 4800 --host 127.0.0.1. Discard the first start after a Defender change, because it is a cold scan.
// spawnlog.cjs: logs every child process the server starts (pid, args, start epoch, duration, exit code)
const cp = require('child_process'); const fs = require('fs'); const out = process.env.SPAWNLOG || 'spawn.ndjson'; const main = require('worker_threads').isMainThread;
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, main, pid: c.pid, 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();Turn on process-creation auditing (auditpol /set /subcategory:"Process Creation" /success:enable and the registry value HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit\ProcessCreationIncludeCmdLine_Enabled=1). Then run this script 3 times. Its serve.cmd holds the step 4 command.
# audstart.ps1: start the server, wait 45 s, dump every process created (event 4688) since the start
$t0 = Get-Date
Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = "cmd.exe /c $PSScriptRoot\serve.cmd" } | Out-Null
Start-Sleep 45
$rows = foreach ($x in Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4688; StartTime=$t0}) { $d=@{}; ([xml]$x.ToXml()).Event.EventData.Data | % { $d[$_.Name]=$_.'#text' }
[pscustomobject]@{ t=$x.TimeCreated.ToString('o'); pid=[Convert]::ToInt32($d.NewProcessId,16); ppid=[Convert]::ToInt32($d.ProcessId,16); name=$d.NewProcessName; parent=$d.ParentProcessName; cl=$d.CommandLine } }
$rows | ConvertTo-Json | Set-Content "$PSScriptRoot\aud-start.json"
foreach($p in (Get-NetTCPConnection -LocalPort 4800 -State Listen).OwningProcess){ Stop-Process -Id $p -Force }// gitconhost.cjs <aud-start.json>: server git processes, and which ones got a conhost child
const a=[].concat(JSON.parse(require("fs").readFileSync(process.argv[2],"utf8").replace(/^\uFEFF/,""))).sort((x,y)=>x.t.localeCompare(y.t));
const g=a.filter(e=>/\\bin\\git\.exe$/.test(e.name)&&/node\.exe$/.test(e.parent||""));const res={};let n=0;
for(const e of g){const c=a.some(x=>x.ppid===e.pid&&/conhost/.test(x.name)&&x.t>=e.t&&Date.parse(x.t)-Date.parse(e.t)<2000);if(c)n++;
const k=(c?"CONHOST ":"none ")+(e.cl||"").replace(/^"[^"]*"\s*/,"").replace(/C:\S+/g,"<path>").slice(0,110);res[k]=(res[k]||0)+1}
console.log("server git",g.length,"with conhost",n);for(const [k,v] of Object.entries(res).sort())console.log(v,k);Where the time goes
packages/shared/src/shell.ts,runsGitWithoutConsole/CONSOLE_FREE_GIT_READS(from perf(server): Windows git reads no longer start a console host #19288). Only exact forms on the list spawn withdetached: true, windowsHide: true, which starts no console host. The list hasrev-parse --show-toplevel,remote,config --get *and a few more. It does not haveconfig --get-all *,config --get-regexp *,remote -v,for-each-ref …orrev-parse --verify --quiet --symbolic-full-name *. It strips a leading--git-dir <dir>but not-C <dir>.- Only
apps/server/src/vcs/GitVcsDriverCore.ts(the spawn inexecuteGit,forceKillAfter: "1 second"block) consults it.apps/server/src/project/RepositoryIdentityResolver.ts(resolveCacheKey,resolveFromCacheKey) runs git throughapps/server/src/processRunner.tsrun, which never setsdetached. So its 3 reads per project always get a console, evenrev-parse --show-toplevel, which is on the list.
Why it is avoidable
Every form in the table reads config or refs only. It starts no hook, helper, pager, editor or lazy fetch, which is the property the allowlist exists for. They get a console host only because the list is narrower than the read forms the server actually runs, and because the identity resolver bypasses it.
What a fix has to show
The same audited start, 3 times before and after, on the same seed:
- Console hosts under server git processes per warm start drop from 38 to 0 for the forms in the table: identity reads 18 → 0 and driver reads 20 → 0. Total processes per start drop by 38.
- What stays: the git processes themselves (their number is Each branch pull-request lookup on Windows starts 14 git processes, and 5 of them re-read what the same lookup already read: 42 git at every server start for 3 branches #40089's and Switching to a thread in another project on Windows starts ~90 git processes, and 5–6 base-branch lookups with the same answer account for 29–36 of them #39984's to reduce; count them separately) and a console for git forms that can start a hook, helper, credential prompt or pager (fetch, push, commit, worktree add, status).
- Results and error handling of the identity resolver and the driver reads do not change.
Found by the automated Windows performance sweep on b568fcb.
Found by the automated Windows performance sweep on b568fcb.
Activity