Repository navigation
Description
What is slow
When a user deletes a thread and chooses to delete its worktree, the web client calls vcs.removeWorktree and, as soon as it returns, vcs.refreshStatus for the project root (apps/web/src/hooks/useThreadActions.ts, the delete flow after removeWorktree). The server's vcs.removeWorktree handler (apps/server/src/ws.ts, WS_METHODS.vcsRemoveWorktree) has already started refreshGitStatus(input.cwd) for that same root. The client's request arrives while that refresh is running. VcsStatusBroadcaster.shareQueuedRefreshStatus queues a follow-up for it, so a second full status refresh runs right after the first. Nothing changed between the two. The user's machine pays for both. The client's refreshStatus answers only after the second one finishes. A failure toast for the cleanup waits on that answer.
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 --localof this repository (32,168 tracked files). Itsoriginis a local bare clone, branchworkpushed with-u. - 6 runs over the app's own WebSocket from a paired page. Git counts are
runGitCommandspans in the server trace.
| run | remove (ms) | client refreshStatus (ms) | refresh 1 (git / ms) | refresh 2 (git / ms) |
|---|---|---|---|---|
| 0 | 5,837 | 2,853 | 30 / 1,499 | 25 / 1,356 |
| 1 | 6,155 | 3,219 | 38 / 1,902 | 25 / 1,321 |
| 2 | 6,215 | 4,101 | 26 / 2,357 | 33 / 1,747 |
| 3 | 5,788 | 3,247 | 30 / 1,507 | 33 / 1,742 |
| 4 | 6,317 | 3,406 | 38 / 2,028 | 25 / 1,380 |
| 5 | 6,150 | 4,191 | 26 / 2,349 | 33 / 1,844 |
Median client refreshStatus: 3.33 s (2.85-4.19). In total, 55-67 git run under ws.rpc.vcs.removeWorktree after the removal itself (3 git).
Span tree of run 2:
6212ms git=63 ws.rpc.vcs.removeWorktree
+1 6211ms git=4 GitWorkflowService.removeWorktree
+6212 2357ms git=59 VcsStatusBroadcaster.shareQueuedRefreshStatus
+6213 4104ms git=59 VcsStatusBroadcaster.runQueuedRefreshes
+6213 2357ms git=26 VcsStatusBroadcaster.refreshStatus <- server's own refresh
+8570 1747ms git=33 VcsStatusBroadcaster.refreshStatus <- follow-up queued by the client's vcs.refreshStatus
4095ms git=0 ws.rpc.vcs.refreshStatus (waits on the follow-up)
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. - 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 to127.0.0.1:4800. node wtrm.cjs <playwright dir> <pairUrl> <p0> 6 out.json. The Playwright dir isnode_modules/.pnpm/playwright@*/node_modules/playwright.- Copy
<home>/userdata/logs/server.trace.ndjson*, thennode sum.cjs ws.rpc.vcs.removeWorktree VcsStatusBroadcaster.refreshStatus <traces>.
// wtrm.cjs <playwrightDir> <pairUrl> <repoDir> <runs> <out.json>
// Each run: vcs.createWorktree, wait, then as the thread delete does: vcs.removeWorktree force:true, then vcs.refreshStatus on the project.
const [pw, pairUrl, repo, runs, out] = process.argv.slice(2);
const { chromium } = require(pw); const fs = require("fs");
(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 rpc = (tag, payload, id) => p.evaluate(async ({ tag, payload, id }) => {
const ws = window.__ws.filter((w) => w.readyState === 1).at(-1);
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, value: m.exit.value }); } } };
ws.addEventListener("message", on);
ws.send(JSON.stringify({ _tag: "Request", id, tag, payload, headers: [] })); });
}, { tag, payload, id });
const res = [];
for (let i = 0; i < +runs; i++) {
const c = await rpc("vcs.createWorktree", { cwd: repo, refName: "work", newRefName: `wt-${Date.now()}`, baseRefName: "work", path: null }, String(700000000 + i * 3));
await p.waitForTimeout(8000);
const r = await rpc("vcs.removeWorktree", { cwd: repo, path: c.value.worktree.path, force: true }, String(700000001 + i * 3));
const s = await rpc("vcs.refreshStatus", { cwd: repo }, String(700000002 + i * 3));
const row = { run: i, create: c.ms, remove: r.ms, refresh: s.ms };
console.log(JSON.stringify(row)); res.push(row); await p.waitForTimeout(8000);
}
fs.writeFileSync(out, JSON.stringify(res)); await b.close();
})();// sum.cjs <rootSpanName> <childNamesCsv> <trace...>: per root span: duration, git total, and per named descendant: count/ms/git
const fs = require("fs"); const [name, csv, ...files] = process.argv.slice(2); const names = csv ? csv.split(",") : []; 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 desc = (s) => { const o = []; const 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; };
for (const root of [...sp.values()].filter((s) => s.name === name).sort((a, b) => st(a) - st(b))) {
const d = desc(root); const gitN = d.filter((c) => c.name === "runGitCommand").length;
const parts = names.map((n) => { const m = d.filter((c) => c.name === n); return `${n}=${m.length}x/${Math.round(m.reduce((a, c) => a + c.durationMs, 0))}ms/git${m.reduce((a, c) => a + desc(c).filter((x) => x.name === "runGitCommand").length, 0)}`; });
console.log(`${Math.round(root.durationMs)}ms git=${gitN} ${parts.join(" ")}`);
}Where the time goes
apps/server/src/ws.ts, theWS_METHODS.vcsRemoveWorktreehandler:Effect.tap(() => refreshGitStatus(input.cwd))forks a full refresh of the project root after the removal.apps/web/src/hooks/useThreadActions.ts, the thread delete flow: afterremoveWorktreesucceeds it awaitsrefreshVcsStatus({ input: { cwd: threadProject.workspaceRoot } }).apps/server/src/vcs/VcsStatusBroadcaster.ts,shareQueuedRefreshStatus/runQueuedRefreshes: a request made during a running refresh gets a follow-up read that starts after it. That is deliberate in general, but here the running refresh already started after the removal.
Why it is avoidable
Both refreshes start after the worktree is gone and read the same unchanged project root. One of them already gives the result the user needs. The second is there only because two layers each ask for the same refresh.
What a fix has to show
The same 6-run driver, before and after, on the same seed:
- Under
ws.rpc.vcs.removeWorktreeplus the client'svcs.refreshStatus,VcsStatusBroadcaster.refreshStatusruns once per delete, down from twice. Git after the removal drops from 55-67 to at most 38. - The client's cleanup answer (
refreshStatus, or whatever replaces it) arrives under 2.5 s after the removal, down from 3.33 s median.
What stays:
- the removal itself (5.8-6.3 s, mostly deleting 32k files; 3 git);
- one full refresh of the project root (26-38 git, 1.5-2.4 s);
refreshLocalStatusfor the removed path;- a cleanup failure must still reach the user's toast.
Open PR #37774 adds a status read before the removal, to warn about uncommitted changes. That is a different cause and is not counted here.
Found by the automated Windows performance sweep on c1464d6.
Found by the automated Windows performance sweep on c1464d6.
Activity