Registry Mirror
Skip to content

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

Done

Description

@juliusmarminge

What is slow

A user types a commit message and clicks Commit (git.runStackedAction with action: "commit" and commitMessage). No message has to be generated. The server still prepares a full temporary commit context first. It copies the index into a temp directory, expands it, runs git add -A into it, checks for conflicts, and lists the staged names. All of that only tells it whether anything is to be committed. Then commit stages the whole worktree again into the real index and commits. On a large repository the user waits for two whole-worktree staging passes.

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, Defender on. Commit 511447a9f2, server from source.
  • A clone of this repository (32,168 files, index 4.5 MB), no remote, branch feature-5, with user.name/user.email set. Before each run, 3 tracked files get a line appended.
  • 6 commits sent over the app's own WebSocket from a paired page:
median (range)
click to result 2,194 ms (2,164-2,443)
runStackedAction span 2,188 ms
statusDetails (initial status) 607 ms
prepareCommitContext 680 ms (662-705, n=7)
commit 812 ms
git processes per commit 20
  • prepareCommitContext runs 6 git: rev-parse --git-path index --git-path objects, count-objects -v, update-index --no-split-index (~60 ms), add -A into the temp index (~275 ms), diff --cached --diff-filter=U (~165 ms), and diff --cached --name-status (~60 ms). It also copies the 4.5 MB index. commit then runs commit.unmergedPaths (~165 ms) and commit.addAll (~275 ms) again on the real index, followed by commit and rev-parse HEAD.
  • GitVcsDriver.commit.addAll and GitVcsDriver.commit.unmergedPaths appear twice in every commit (6/6).

How to measure it again

  1. Check out the commit, vp i, cd apps/web && vp build. git clone --local <a t3code checkout> p5, git remote remove origin, git checkout -b feature-5, 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 (production build) and node src/bin.ts project add <p5> --base-dir <home>. Mint a pairing URL with node src/bin.ts pair --ttl 1h --base-dir <home> and set its host to 127.0.0.1:4800.
  3. node gitact.cjs <playwright dir> <pairUrl> <p5> 6 commit out.json, then V=1 node under.cjs runStackedAction <home>/userdata/logs/server.trace.ndjson*.
// gitact.cjs <playwrightDir> <pairUrl> <repoDir> <runs> <action> <out.json>: per run, append to 3 tracked files, then send
// git.runStackedAction over the page's own WebSocket with a commit message (no generation). Records wall time and progress events.
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 r = await p.evaluate(async ({ cwd, i, action }) => { 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, commitMessage: `perf ${action} ${i}` }, headers: [] })); }); }, { cwd: repo, i, action });
    r.run = i; console.log(JSON.stringify(r)); res.push(r); await p.waitForTimeout(6000); }
  fs.writeFileSync(out, JSON.stringify(res)); await b.close(); })();
// under.cjs <spanName> <trace...>: per span of that name, duration and git processes grouped by their operation (V=1 for detail)
const fs=require("fs");const [name,...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 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 st=s=>Number(BigInt(s.startTimeUnixNano)/1000000n);
for(const s of [...sp.values()].filter(s=>s.name===name).sort((a,b)=>st(a)-st(b))){const g=desc(s).filter(x=>x.name==="runGitCommand");const by={};
 for(const x of g){const k=sp.get(x.parentSpanId)?.name||"?";(by[k]=by[k]||[]).push(Math.round(x.durationMs))}
 console.log(Math.round(s.durationMs)+"ms","git="+g.length,s.exit?._tag);
 if(process.env.V)for(const [k,v] of Object.entries(by))console.log("   ",v.length,k,v.join(","))}

Where the time goes

apps/server/src/git/GitManager.ts, runCommitStep calls resolveCommitAndBranchSuggestion. With a custom message, that function still calls gitCore.prepareCommitContext(cwd, filePaths, { includePatch: false }) and only uses the result as a "there are changes" check. In apps/server/src/vcs/GitVcsDriverCore.ts, prepareCommitContext builds a temp index and object directory, copies and expands the index, runs stageCommitChanges into it (add -A and the unmerged check), then diff --cached --name-status. Next, commit runs stageCommitChanges again on the real index and commits. runStackedAction has already read statusDetails (607 ms) at that point, and it lists the changed files.

Why it is avoidable

With a supplied message, the throwaway index only answers whether anything would be committed. The initial status already knows that, and the real staging pass that follows recomputes it. The one case it guards, a merge resolved to HEAD's tree, is a cheap MERGE_HEAD check.

What a fix has to show

The same 6 commits before and after, on the same seed:

  • Git processes per commit with a typed message drop from 20 to at most 15, and GitVcsDriver.commit.addAll runs once per commit, from twice.
  • Click to result drops by about the prepareCommitContext time: ~1.5 s, from 2.19 s.
  • What stays: the initial status read (~0.6 s), one staging pass with its conflict check, git commit and rev-parse HEAD (~0.8 s). Behaviour must be the same for "nothing to commit", a merge whose result equals HEAD, selected-file (partial) commits, and hooks. Generated messages still need the staged patch, so they are out of scope.
  • Not counted here: the status refresh after the commit (42 git; the no-remote part is filed separately).

Found by the automated Windows performance sweep on 511447a.


Found by the automated Windows performance sweep on 511447a.

Activity

  1. added a commit that references this issue on Nov 21, 2026
    a132058
  2. Sharad-Patel1 commented on Nov 22, 2026

    @Sharad-Patel1
    Contributor

    Note

    Generated by claude-opus-5-5
    RESPONDING ON BEHALF OF SHARAD

    This can be closed: #40282 (69228fe) fixes it on main. It first shipped in v0.1.12-nightly.20261121.5051, with no stable release yet. The PR says "Refs" rather than "Fixes", so it didn't close this issue on merge. runCommitStep now builds the suggestion straight from a typed message and skips prepareCommitContext. commit stages the real index once (GitVcsDriverCore.ts). It only builds the throwaway index when git diff --cached --quiet shows something already staged, and in the issue's setup nothing is. Nothing to commit still returns skipped_no_changes, and a merge resolved to HEAD still commits after a MERGE_HEAD check.

    The git process count misses the issue's target by one. The fix adds two git diff --cached --quiet checks (commit.indexChanges and commit.stagedChanges, 14 and 15 ms here), so a typed commit starts 4 fewer git processes, not 5. Applied to the issue's 20, that would be 16, not "at most 15". commit.addAll does run once. I didn't measure on Windows. Two cases still stage twice by design: a commit with changes already staged, and a generated message, which the issue leaves out of scope.

    The attached script adds one test to GitManager.test.ts. It uses the harness from the fix's own test, which records every git process the manager starts. The test copies the issue's setup, 3 tracked files with a line appended to each and nothing staged, then runs a typed-message runStackedAction commit. Before #40282 the commit runs add -A twice and expands a throwaway index (update-index --no-split-index). On current main it runs add -A once and builds no throwaway index. Both commits contain all 3 files and leave a clean tree. The output lists every git process, 24 before and 20 on main.

    I also checked it in the real app with the issue's setup. Nothing is simulated. The project is a no-remote clone of this repository at 511447a (33,228 files). I appended a line to README.md, package.json and AGENTS.md, then committed from the Git actions menu with the typed message "perf commit 1". I counted git processes under the runStackedAction span with the issue's under.cjs. Before #40282 the commit took 1,671 ms and 25 git processes, with commit.addAll and commit.unmergedPaths twice each and four prepareCommitContext steps. On main it took 1,093 ms and 21 git processes, with commit.addAll once and no prepareCommitContext. Both commits contain the same 3 files. The status reads around the commit differ from the build in the issue, so neither total is 20. This was one commit each on macOS, so treat the timings as rough.

    Before #40282 (66441268e8) main (63fa4c892e)
    Before #40282 (66441268e8) main (63fa4c892e)
    📹 Screen recording 📹 Screen recording

    To reproduce, run bash prove-issue-40248.sh from a clean t3code checkout after vp i.

    Result
    PASS  #40282 (69228fe179) is on main: fix(server): typed-message commits stage the worktree once (#40282)
    PASS  before #40282 (66441268e8): the typed commit is created with all 3 files, after 2 `add -A` runs and 1 throwaway-index expansion (`update-index --no-split-index`)
    PASS  main (63fa4c892e): the same typed commit is created with all 3 files, after 1 `add -A` run and no throwaway index
    VERDICT: #40248 is fixed on main by #40282
    
  3. juliusmarminge commented on Nov 23, 2026

    @juliusmarminge
    MemberAuthor

    #40282, now on main: Typed-message commits with an unchanged index now skip the throwaway commit context and stage the worktree once, with regression coverage for empty results, selected files and merges resolved to HEAD's tree.

    Not done: The issue still requires six before/after Windows runs on the same seed demonstrating at most 15 git processes and approximately 1.5-second click-to-result time; the merged PR explicitly leaves those measurements unverified.

    Closing; open a new issue if what is left still matters to you.

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