Skip to content

Every git status refresh of a repository with no remote runs ~11 git looking for remotes, pull requests and a hosting provider it cannot have (~440 ms of git time per refresh on Windows) #40249

Closed

Description

@juliusmarminge

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 origin removed (git remote -v is empty), branch feature-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

  1. 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.
  2. From apps/server: start T3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir <home> --port 4800 --host 127.0.0.1 and node src/bin.ts project add <p5> --base-dir <home>. Trigger refreshes with a few commits: append a line to a tracked file, then send git.runStackedAction with action: "commit" and a commitMessage (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.
  3. 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), then readRemoteUrlNullable(cwd, preferred) and readRemoteUrlNullable(cwd, "origin"). With no remote, both URL reads fail.
  • GitManager.ts, lookupStatusPr, through getPrLookup: resolveLookupHeadContext (resolveBranchHeadContext reading branch remote config and readRemoteUrl, findPublishedBranchRemote listing remotes) and isUnpublishedBranch (config and a ref read).
  • apps/server/src/vcs/GitVcsDriverCore.ts, resolvePrimaryDefaultBranchName: resolveDefaultBranchName(cwd, "origin") and then listRemoteNames. It is called by both the local and the remote half of each refresh.
  • The local half already runs statusDetails.primaryRemoteExists in 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:


Found by the automated Windows performance sweep on 511447a.


Found by the automated Windows performance sweep on 511447a.

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