Skip to content

Pull on Windows reads the full working-tree git status twice: the read after the pull costs 660 ms and 12 git of a 1.86 s click to get the upstream name it already had #40313

Closed

Description

@juliusmarminge

What is slow

A user clicks Pull (vcs.pull). GitVcsDriverCore.pullCurrentBranch runs readStatusDetailsLocal once before the pull and again after it. Each read runs the worktree-wide git status --porcelain=2 and git diff --numstat, plus computeAheadCountAgainstBase. From the first read the function uses only branch and hasUpstream. From the second it uses only upstreamRef, for the result. The user waits for both reads before the pull answers. The status broadcast that follows (refreshGitStatus, 38 git) then reads everything again for the UI.

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on. Commit c1464d6774, server from source serving the production web build.
  • Seed: git clone --local of this repository (32,168 tracked files) as p0, and a second clone p1, both with origin set to a local bare clone and on branch work tracking origin/work. Before each run p1 pushes 3 new commits, so p0 is 3 behind.
  • 6 runs per scenario over the app's own WebSocket from a paired page. Git counts are runGitCommand spans in the server trace.
scenario click to result, median (range) git in pullCurrentBranch
3 commits behind 1,864 ms (1,852-1,936) 22
already up to date 1,517 ms (1,493-1,595) 22

Span tree of one pull (behind):

1819ms git=22 pullCurrentBranch
  +2     463ms git=6  readStatusDetailsLocal            (uses branch, hasUpstream)
    +61    318ms        statusDetails.status
    +61    270ms        statusDetails.numstat
    +379    86ms git=2  computeAheadCountAgainstBase
  +465    28ms  git=1  readConfigValue branch.<b>.remote
  +493    40ms  git=1  pullCurrentBranch.beforeSha
  +533   585ms  git=1  pullCurrentBranch.pull           (git pull --ff-only)
  +1118   40ms  git=1  pullCurrentBranch.afterSha
  +1158  662ms  git=12 readStatusDetailsLocal           <- re-read, uses only upstreamRef
    +1217  315ms        statusDetails.status
    +1218  272ms        statusDetails.numstat
    +1532  288ms git=8  computeAheadCountAgainstBase
+1850 2071ms git=38 VcsStatusBroadcaster.refreshStatus (broadcast after the answer)

The up-to-date pull has the same shape: reads 479 ms + ~660 ms around a 230 ms git pull.

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. For p0 and p1: git clone -q --local <t3code checkout> <p>, set user.name/user.email, git remote set-url origin <abs>/bare.git, git fetch origin, git checkout -B work origin/main, git push -u origin work.
  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>, node src/bin.ts pair --ttl 1h --base-dir <home>. Set the pairing URL's host to 127.0.0.1:4800.
  4. node pull.cjs <playwright dir> <pairUrl> <p0> <p1> 6 out.json, then the same with UPTODATE=1. The Playwright dir is node_modules/.pnpm/playwright@*/node_modules/playwright.
  5. Copy <home>/userdata/logs/server.trace.ndjson*, then node sum.cjs ws.rpc.vcs.pull readStatusDetailsLocal,GitVcsDriver.pullCurrentBranch.pull <traces> (the sum.cjs from the thread-delete worktree issue of the same sweep: per root span, duration, git total and per named descendant count/ms/git). Note that readStatusDetailsLocal=3x there includes the broadcast's read.
// pull.cjs <playwrightDir> <pairUrl> <repoDir> <upstreamPeerDir> <runs> <out.json>
// Each run: peer commits+pushes 3 commits (UPTODATE=1 skips), then the page sends vcs.pull for repoDir.
const [pw, pairUrl, repo, peer, runs, out] = process.argv.slice(2);
const { chromium } = require(pw); const fs = require("fs"); const path = require("path"); const cp = require("child_process");
const g = (d, ...a) => cp.execFileSync("git", ["-C", d, ...a], { stdio: ["ignore", "pipe", "ignore"] }).toString();
(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.UPTODATE) {
      g(peer, "pull", "-q", "--ff-only");
      for (let k = 0; k < 3; k++) { fs.appendFileSync(path.join(peer, "apps", "server", `pull-${k}.txt`), `pull ${i} ${k} ${Date.now()}\n`); g(peer, "add", "-A"); g(peer, "commit", "-qm", `peer ${i} ${k}`); }
      g(peer, "push", "-q");
    }
    await p.waitForTimeout(5000);
    const r = await p.evaluate(async ({ cwd, i }) => {
      const ws = window.__ws.filter((w) => w.readyState === 1).at(-1); const id = String(800000000 + i);
      return await new Promise((resolve) => { const t0 = performance.now();
        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 === "Exit") { ws.removeEventListener("message", on); resolve({ ms: Math.round(performance.now() - t0), exit: m.exit._tag, v: JSON.stringify(m.exit.value ?? m.exit.cause).slice(0, 200) }); } } };
        ws.addEventListener("message", on);
        ws.send(JSON.stringify({ _tag: "Request", id, tag: "vcs.pull", payload: { cwd }, headers: [] })); });
    }, { cwd: repo, i });
    r.run = i; console.log(JSON.stringify(r)); res.push(r); await p.waitForTimeout(7000);
  }
  fs.writeFileSync(out, JSON.stringify(res)); await b.close();
})();

Where the time goes

apps/server/src/vcs/GitVcsDriverCore.ts, pullCurrentBranch:

  • starts with const details = yield* readStatusDetailsLocal(cwd) and reads only details.branch and details.hasUpstream;
  • ends with const refreshed = yield* readStatusDetailsLocal(cwd) and reads only refreshed.upstreamRef.

Each readStatusDetailsLocal runs git status (315-330 ms), git diff --numstat (270 ms, in parallel) and computeAheadCountAgainstBase (2-8 git, 86-288 ms).

Why it is avoidable

git pull --ff-only does not change the branch's upstream configuration, so the upstream name read after the pull is the one known before it. Neither read uses the file list, line counts or ahead-of-base count that make it expensive. The status the UI shows is re-read by the broadcast after the answer anyway.

What a fix has to show

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

  • git in pullCurrentBranch from 22 to at most 10;
  • 3 behind: click to result under 1.3 s, from 1.86 s;
  • up to date: under 1.0 s, from 1.52 s.

What stays:

  • git pull --ff-only (230-600 ms);
  • the before/after rev-parse HEAD that decides pulled versus skipped_up_to_date (~80 ms);
  • reading the branch and whether it has an upstream before pulling (detached HEAD and no-upstream errors must stay);
  • the claim on a queued status fetch;
  • the status broadcast after the answer (38 git), which updates every client.

Push has the same pattern for a different function (#40278, pushCurrentBranch/buildCompletionToast); this is the separate vcs.pull path.


Found by the automated Windows performance sweep on c1464d6.


Found by the automated Windows performance sweep on c1464d6.

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