Repository navigation
Description
What is slow
Many projects are local repositories with no git remote. For those, each status refresh still runs the parts of status that only make sense with a remote. The local half asks for branch.<b>.remote and reads the URL of origin twice (resolveHostingProvider), and it looks up origin's default branch and lists the remotes. The remote half does the same default-branch lookup and runs the status PR lookup (lookupStatusPr: branch remote config, remote URL, remote listing for a published branch, unpublished-branch checks). The answer to all of them is "none". A refresh runs after every commit, on every 30-s remote poll for each open thread, and on thread switches, so these processes take CPU from whatever the user is waiting on.
Measured
- Windows Server 2025, 4 vCPU, 16 GB, Defender on. Commit
511447a9f2, server from source. - A clone of this repository (32k files) with
originremoved (git remote -vis empty), branchfeature-5. - 11 status refreshes over a 212-s trace (6 of them after commits made through
git.runStackedAction), with an average of git processes per refresh:
| part of the refresh | git per refresh | median duration |
|---|---|---|
GitWorkflowService.localStatus total |
17.0 | |
GitWorkflowService.remoteStatus total |
12.6 | |
lookupStatusPr (remote half) |
4.1 | 221 ms |
resolveHostingProvider (local half) |
3.0 (11/11) | 130 ms |
GitVcsDriver.resolvePrimaryDefaultBranchName (both halves) |
3.5 | ~90 ms each |
- That is about 10.6 of ~30 git per refresh, ~440 ms of git time, spent looking for remotes in a repository that has none. One refresh after a commit ran 42 git over 2.46 s (
VcsStatusBroadcaster.refreshStatus).
How to measure it again
- Check out the commit,
vp i.git clone --local <a t3code checkout> p5,git remote remove origin,git checkout -b feature-5, commit one file,git config user.name perf,git config user.email perf@example.com. - From
apps/server: startT3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir <home> --port 4800 --host 127.0.0.1andnode src/bin.ts project add <p5> --base-dir <home>. Trigger refreshes with a few commits: append a line to a tracked file, then sendgit.runStackedActionwithaction: "commit"and acommitMessage(a driver that does this over the page's WebSocket is in the companion commit issue from this sweep). Alternatively, keep a thread of the project open in the web client for a few minutes so the 30-s remote poll runs. - Copy
<home>/userdata/logs/server.trace.ndjson*and run:
// statusreads.cjs <trace...>: per local/remote status read, git processes grouped by the remote-related operation that ran them
const fs=require("fs");const sp=new Map();for(const f of process.argv.slice(2))for(const l of fs.readFileSync(f,"utf8").split("\n")){try{const r=JSON.parse(l);if(r.type==="effect-span")sp.set(r.spanId,r)}catch{}}
const kids=new Map();for(const s of sp.values()){const k=kids.get(s.parentSpanId)||[];k.push(s);kids.set(s.parentSpanId,k)}
const desc=s=>{const o=[],q=[s];while(q.length){const x=q.pop();for(const c of kids.get(x.spanId)||[]){o.push(c);q.push(c)}}return o};
const anc=(g,re)=>{let x=sp.get(g.parentSpanId);while(x){if(re.test(x.name))return x.name;x=sp.get(x.parentSpanId)}return null};
const RE=/^(lookupStatusPr|resolveHostingProvider|GitVcsDriver.resolvePrimaryDefaultBranchName|resolvePrimaryRemoteName|statusDetailsRemote|readStatusDetailsLocal|readBranchChangeTotals)$/;
for(const name of ["GitWorkflowService.remoteStatus","GitWorkflowService.localStatus"]){const rs=[...sp.values()].filter(s=>s.name===name);const by={};let tot=0;
for(const r of rs){const g=desc(r).filter(x=>x.name==="runGitCommand");tot+=g.length;for(const x of g){const k=anc(x,RE)||sp.get(x.parentSpanId).name;by[k]=(by[k]||0)+1}}
console.log(name,"n",rs.length,"git/read",(tot/rs.length).toFixed(1));for(const [k,v] of Object.entries(by).sort((a,b)=>b[1]-a[1]))console.log(" ",(v/rs.length).toFixed(1),k)}
for(const n of ["lookupStatusPr","resolveHostingProvider"]){const v=[...sp.values()].filter(s=>s.name===n).map(s=>s.durationMs).sort((a,b)=>a-b);console.log(n,v.length,"median ms",Math.round(v[v.length>>1]))}Where the time goes
apps/server/src/git/GitManager.ts,resolveHostingProvider:readConfigValueNullable(branch.<b>.remote), thenreadRemoteUrlNullable(cwd, preferred)andreadRemoteUrlNullable(cwd, "origin"). With no remote, both URL reads fail.GitManager.ts,lookupStatusPr, throughgetPrLookup:resolveLookupHeadContext(resolveBranchHeadContextreading branch remote config andreadRemoteUrl,findPublishedBranchRemotelisting remotes) andisUnpublishedBranch(config and a ref read).apps/server/src/vcs/GitVcsDriverCore.ts,resolvePrimaryDefaultBranchName:resolveDefaultBranchName(cwd, "origin")and thenlistRemoteNames. It is called by both the local and the remote half of each refresh.- The local half already runs
statusDetails.primaryRemoteExistsin the same refresh, so "this repository has no remote" is known before these run.
Why it is avoidable
With zero remotes configured, every one of these reads can only return "no remote, no default branch, no provider, no pull request". One read of the remote list per refresh answers them all.
What a fix has to show
The same trace on the same seed (a no-remote repository, 6+ refreshes), before and after:
- Git processes per local+remote refresh drop by at least 9, from ~30 to ~21 or fewer.
lookupStatusPrandresolveHostingProviderrun no git when the repository has no remote, andresolvePrimaryDefaultBranchNameruns at most once per refresh. - What stays: one read that establishes there is no remote (today
statusDetails.primaryRemoteExists), the status, numstat and branch totals, and identical status output (hasPrimaryRemote: false, no PR, no hosting provider). As soon as a remote is added, status must show the PR and provider on the next refresh, so a cached "no remote" has to follow the repository config. - Not counted here: base-branch lookups (
resolveBaseBranchForNoUpstream/resolvePrimaryRemoteName, cached by perf(server): resolve a branch's base once while its refs and config are unchanged #40125); the upstream/HEAD re-reads instatusDetailsRemote(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, merged as perf(server): remote status polls read HEAD, upstream and remotes once #40162 after this commit); PR lookups for repositories that do have a remote (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/perf(server): branch PR lookups start 9 git processes instead of 14 #40153).
Found by the automated Windows performance sweep on 511447a.
Found by the automated Windows performance sweep on 511447a.
Activity