Description
What is slow
When a user commits selected files (git.runStackedAction with action: "commit" and filePaths), GitVcsDriverCore's commit step first checks that no merge, cherry-pick or revert is in progress. It runs one git rev-parse --git-path MERGE_HEAD --git-path CHERRY_PICK_HEAD --git-path REVERT_HEAD --git-path sequencer and checks those files on disk. Then, for each of CHERRY_PICK_HEAD and REVERT_HEAD whose file is missing, which is the normal case, it starts another git rev-parse --verify --quiet --symbolic-full-name <head> (GitVcsDriver.commit.operationRef). Those two probes exist for reftable repositories, which keep these heads as refs with no file. In an ordinary files-backend repository a missing file already answers the question. The probes still run on every partial commit.
Measured
- Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on. Commit
c1464d6774, server from source. - Seed:
git clone --localof this repository (32,168 tracked files, files ref backend), branchworkwith a local bareorigin. - 6 partial commits (3 files edited,
filePaths: ["README.md"], typed message) over the app's WebSocket. - Click to result: 2,184 ms median (1,978-2,679).
runCommitStep: 16-17 git, 1.38-2.05 s. GitVcsDriver.commit.operationRef: 2 spans and 2 git on 6 of 6 commits, 79-87 ms per commit (one outlier at 286 ms). They run one after the other, aftercommit.mergeHead(1 git, ~43 ms).
+608 748ms git=8 commit
+608 43ms git=1 GitVcsDriver.commit.mergeHead
+652 41ms git=1 GitVcsDriver.commit.operationRef <- CHERRY_PICK_HEAD
+693 39ms git=1 GitVcsDriver.commit.operationRef <- REVERT_HEAD
+733 49ms git=1 GitVcsDriver.commit.unmergedPaths
+781 177ms git=1 GitVcsDriver.commit.reset
+959 87ms git=1 GitVcsDriver.commit.addSelected
+1046 270ms git=1 GitVcsDriver.commit.commit
+1315 40ms git=1 GitVcsDriver.commit.revParseHead
How to measure it again
- Check out the commit,
vp i,cd apps/web && vp build. - Seed:
git clone -q --bare --local <t3code checkout> bare.git,git clone -q --local <t3code checkout> p0. Inp0: setuser.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.git -C p0 rev-parse --show-ref-formatprintsfiles. - 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>(pairing URL host set to127.0.0.1:4800). - Send 6 commits over the page's socket with the driver below:
PARTIAL=1 node gitact2.cjs <playwright dir> <pairUrl> <p0> 6 commit out.json. The Playwright dir isnode_modules/.pnpm/playwright@*/node_modules/playwright. - Copy
<home>/userdata/logs/server.trace.ndjson*and count spans namedGitVcsDriver.commit.operationRefperrunCommitStep(each span has onerunGitCommandchild).
// gitact2.cjs <playwrightDir> <pairUrl> <repoDir> <runs> <action> <out.json>; 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");
(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++) {
for (const f of ["README.md", "package.json", "AGENTS.md"]) fs.appendFileSync(path.join(repo, f), `\n${action} ${i} ${Date.now()}\n`);
await p.waitForTimeout(4000);
const 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 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 }));
if (m._tag === "Exit") { ws.removeEventListener("message", on); resolve({ ms: Math.round(performance.now() - t0), exit: m.exit._tag }); } } };
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();
})();Where the time goes
apps/server/src/vcs/GitVcsDriverCore.ts, the partial-commit branch of the commit step (filePaths set, no private index env): isOperationRef runs GitVcsDriver.commit.operationRef for each of CHERRY_PICK_HEAD and REVERT_HEAD whose --git-path file does not exist (Effect.filterOrElse(... () => isOperationRef(head))). The comment above it gives the reason: reftable keeps these heads as refs with no file under .git.
Why it is avoidable
The probes only matter when the repository uses the reftable backend. In a files-backend repository, which is what almost every user has, a missing CHERRY_PICK_HEAD/REVERT_HEAD file means no operation is in progress. The repository's ref format can be known without a git process per head per commit.
What a fix has to show
The same 6 partial commits, before and after, on a files-backend repository:
GitVcsDriver.commit.operationRefruns 0 times per commit, down from 2. Git inrunCommitStepgoes from 16-17 to at most 15, and the commit step is ~80 ms shorter.
What stays:
- the
mergeHeadpath check (1 git); - the refusal during a merge, cherry-pick, revert or sequencer operation, which must still work in both files and reftable repositories (a reftable repository may still pay the probes);
- the rest of the partial commit (
prepareCommitContextis Committing with a typed message on Windows stages the whole worktree twice: a throwaway index costs 6 of 20 git and 680 ms of the 2.19 s click #40248 and not counted here).
Found by the automated Windows performance sweep on c1464d6.
Found by the automated Windows performance sweep on c1464d6.
Activity