Skip to content

Push and commit-and-push on Windows read the full working-tree git status three times per click: two of the reads (27-38 git, 1.6-2.2 s) only need the branch and upstream #40278

Closed

Description

@juliusmarminge

What is slow

A user clicks Push or Commit & push (git.runStackedAction with action: "push" or "commit_push"). The server reads the full Git status (statusDetails) three times before it answers:

  1. at the start of runStackedAction;
  2. again at the start of pushCurrentBranch, before it pushes;
  3. again in buildCompletionToast, after the push, to choose the toast's button.

Every read runs the worktree-wide git status and git diff --numstat, the upstream refresh, and the ahead-of-base count. On a large repository each read costs about 0.6-1.2 s. The user waits for all three, although the git push itself takes about 0.4 s.

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on. Commit 0fd4822887, server from source serving the production web build.
  • Seed: git clone --local of this repository (~32k tracked files, 4.5 MB index). Its origin is a local bare clone (git clone --bare --local), branch feature-0 pushed with -u, user.name/user.email set.
  • 6 runs per scenario, sent over the app's own WebSocket from a paired page. Git counts come from runGitCommand spans in the server trace.
scenario click to result, median (range) git in runStackedAction
commit_push (3 files edited, typed message) 5,527 ms (5,453-5,904) 76 (76-81)
push (branch with upstream, 1 local commit) 3,533 ms (3,276-3,601) 52-54
push, first publish (new branch, no upstream) 3,540 ms (3,428-3,783) 56-58

Span tree of one commit_push (76 git):

+0     1064ms git=16 statusDetails                      (initial)
+1064  1515ms git=11 runCommitStep                      (prepareCommitContext 683 ms is #40248)
+2579  1844ms git=28 GitManager.pushCurrentBranch
  +2579  984ms git=19   statusDetails                   <- re-read
  +3563  187ms git=5    resolvePushDestination
  +3750  472ms git=1    pushCurrentBranch.pushUpstream  (git push)
+4424  1372ms git=21 buildCompletionToast
  +4519 1177ms git=19   statusDetails                   <- re-read

The push action (52 git) looks the same: initial 848 ms/14 git, the re-read in pushCurrentBranch 599 ms/8 git with nothing changed since the first read, git push 414 ms, and the toast's read 971 ms/19 git. On the first publish the re-reads cost 590 ms/8 git and 1,224 ms/21 git. After every action the status broadcast (invalidateStatus) runs 25 more git, which is a fourth status read.

How to measure it again

  1. Check out the commit, vp i, cd apps/web && vp build.
  2. Seed: git clone -q --bare --local <t3code checkout> bare.git, then git clone -q --local <t3code checkout> p0. In p0: git config user.name perf, git config user.email [email protected], git checkout -b feature-0, commit one change, git remote set-url origin <abs path>/bare.git, git fetch origin, git push -u origin feature-0.
  3. From apps/server: T3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir <home> --port 4800 --host 127.0.0.1, node src/bin.ts project add <p0> --base-dir <home>, then node src/bin.ts pair --ttl 1h --base-dir <home>. Set the pairing URL's host to 127.0.0.1:4800.
  4. node gitact2.cjs <playwright dir> <pairUrl> <p0> 6 commit_push out.json, then node gitact2.cjs ... 6 push out2.json. For the first publish, set NEWBRANCH=1 and run push. The Playwright dir is node_modules/.pnpm/playwright@*/node_modules/playwright.
  5. Copy <home>/userdata/logs/server.trace.ndjson* right away (it rotates at ~10 MB). Then run node tree.cjs runStackedAction <n> 2 <trace files> for the nth action.
// gitact2.cjs <playwrightDir> <pairUrl> <repoDir> <runs> <action> <out.json>
// NEWBRANCH=1 checks out a fresh branch before each run; PARTIAL=1 sends filePaths:[README.md]
const [pw, pairUrl, repo, runs, action, out] = process.argv.slice(2);
const { chromium } = require(pw); const fs = require("fs"); const path = require("path"); const cp = require("child_process");
(async () => {
  const b = await chromium.launch(); const p = await (await b.newContext()).newPage();
  await p.addInitScript(() => { const O = window.WebSocket; window.__ws = []; window.WebSocket = class extends O { constructor(...a) { super(...a); if (String(a[0]).includes("/ws")) window.__ws.push(this); } }; });
  await p.goto(pairUrl); await p.waitForTimeout(10000); const res = [];
  for (let i = 0; i < +runs; i++) {
    if (process.env.NEWBRANCH) cp.execFileSync("git", ["-C", repo, "checkout", "-q", "-b", `perf-${action}-${Date.now()}`]);
    if (action !== "push") for (const f of ["README.md", "package.json", "AGENTS.md"]) fs.appendFileSync(path.join(repo, f), `\n${action} ${i} ${Date.now()}\n`);
    else { fs.appendFileSync(path.join(repo, "README.md"), `\npush ${i} ${Date.now()}\n`); cp.execFileSync("git", ["-C", repo, "commit", "-qam", `pre ${i}`]); }
    await p.waitForTimeout(4000);
    const extra = {}; if (action !== "push") extra.commitMessage = `perf ${action} ${i}`; if (process.env.PARTIAL) extra.filePaths = ["README.md"];
    const r = await p.evaluate(async ({ cwd, i, action, extra }) => {
      const ws = window.__ws.filter((w) => w.readyState === 1).at(-1); const id = String(900000000 + i);
      return await new Promise((resolve) => { const t0 = performance.now(); const chunks = [];
        const on = (ev) => { let ms; try { ms = [].concat(JSON.parse(ev.data)); } catch { return; }
          for (const m of ms) { if (String(m.requestId) !== id) continue;
            if (m._tag === "Chunk") { ws.send(JSON.stringify({ _tag: "Ack", requestId: id })); for (const v of m.values) chunks.push([Math.round(performance.now() - t0), v.kind, v.phase || ""]); }
            if (m._tag === "Exit") { ws.removeEventListener("message", on); resolve({ ms: Math.round(performance.now() - t0), exit: m.exit._tag, chunks }); } } };
        ws.addEventListener("message", on);
        ws.send(JSON.stringify({ _tag: "Request", id, tag: "git.runStackedAction", payload: { actionId: "perf-" + Date.now(), cwd, action, ...extra }, headers: [] })); });
    }, { cwd: repo, i, action, extra });
    r.run = i; console.log(JSON.stringify(r)); res.push(r); await p.waitForTimeout(6000);
  }
  fs.writeFileSync(out, JSON.stringify(res)); await b.close();
})();
// tree.cjs <spanName> <index> <maxDepth> <trace...>: span tree under the Nth span of that name: +offset ms, duration, git count
const fs = require("fs"); const [name, idx, maxDepth, ...files] = process.argv.slice(2); const sp = new Map();
for (const f of files) 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 st = (s) => Number(BigInt(s.startTimeUnixNano) / 1000000n);
const git = (s) => { let n = 0; const q = [s]; while (q.length) { const x = q.pop(); for (const c of kids.get(x.spanId) || []) { if (c.name === "runGitCommand") n++; q.push(c); } } return n; };
const root = [...sp.values()].filter((s) => s.name === name).sort((a, b) => st(a) - st(b))[+idx]; const t0 = st(root);
const walk = (s, d) => { for (const c of (kids.get(s.spanId) || []).sort((a, b) => st(a) - st(b))) { if (c.name === "runGitCommand") continue; const g = git(c);
  if (g > 0 || d < 2) console.log("  ".repeat(d) + `+${st(c) - t0} ${Math.round(c.durationMs)}ms git=${g} ${c.name}`); if (d < +maxDepth) walk(c, d + 1); } };
console.log(`${Math.round(root.durationMs)}ms git=${git(root)} ${name}`); walk(root, 0);

Where the time goes

  • apps/server/src/git/GitManager.ts, runStackedAction / runAction: reads gitCore.statusDetails(input.cwd) first.
  • apps/server/src/vcs/GitVcsDriverCore.ts, pushCurrentBranch: begins with const details = yield* statusDetails(cwd). From that result it uses only branch, aheadCount, behindCount, hasUpstream and upstreamRef.
  • apps/server/src/git/GitManager.ts, buildCompletionToast: calls gitCore.statusDetails(cwd) for every action except commit. It uses only branch, upstreamRef, hasUpstream and isDefaultBranch.
  • Each statusDetails runs refreshStatusUpstreamIfStale and then readStatusDetailsLocal. The latter runs git status (342-468 ms) and git diff --numstat (293-395 ms) over the whole worktree, plus computeAheadCountAgainstBase (up to 8 git).

Why it is avoidable

Neither later reader uses the working-tree part of the status (file list, line counts), which is what makes a read expensive. In a plain push nothing changes between the first read and the read in pushCurrentBranch. After the push, the toast's branch, upstream and default-branch values are already known from the push result and the initial status.

What a fix has to show

The same 6-run measurements, before and after, on the same seed:

  • push (branch with upstream): git per action from 52-54 to at most 32, and click to result under 2.3 s, from 3.53 s.
  • commit_push: git per action from 76 to at most 52, and click to result under 3.8 s, from 5.53 s.
  • First publish: the same drop, from 56-58 git and 3.54 s.
  • statusDetails (with its git status and git diff --numstat) runs once per action, from three times.

What stays:

Behaviour must stay the same for:


Found by the automated Windows performance sweep on 0fd4822.


Found by the automated Windows performance sweep on 0fd4822.

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