Skip to content

Unarchiving or deleting from Settings → Archived threads downloads the whole archived list 2-3 times per click: about 120 KB per copy at 68 archived threads #40497

Open

Description

@juliusmarminge

What is slow

In Settings → Archived threads, every Unarchive click fetches the full archived snapshot (orchestration.getArchivedShellSnapshot) twice in the same millisecond, and every Delete fetches it three times. Each response carries every archived thread's shell (about 1.9 KB per thread), so at 68 archived threads every extra copy is about 115-127 KB on the wire and 40-170 ms of server work. The row is removed only after a snapshot arrives, so the user waits on this: a delete takes a median 789 ms to disappear. Remote clients pay the extra bytes over the relay.

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, Defender real-time scanning on, commit 194025e.
  • 100 replay threads in two projects (32k-file repositories), 68 of them archived from the sidebar. Headless Chromium on /settings/archived.
  • Unarchive, 7 runs (68→61 archived): getArchivedShellSnapshot sent 2 times per click on every run, both in the same ms about 50 ms after thread.unarchive. Two responses of the same size per click (for example 49,152 + 49,152 + 26,781 bytes received twice). Row gone median 279 ms (250-400).
  • Delete (with Confirm), 7 runs (61→54 archived): 3 snapshots per delete on every run: two in the same ms about 65 ms after thread.delete, then a third 60-100 ms later. 102-114 KB each. Row gone median 789 ms (494-922).
  • Server trace: each orchestration.getArchivedShellSnapshot span took 42-169 ms.
+0   orchestration.getThreadFamily
+7   orchestration.dispatchCommand {"type":"thread.delete",...}
+72  orchestration.getArchivedShellSnapshot {}
+73  orchestration.getArchivedShellSnapshot {}
+135 orchestration.getArchivedShellSnapshot {}

How to measure it again

  1. Check out the commit in C:/p/wt, run vp i, then vp build in apps/web.
  2. Make a large repository with a remote: git clone --bare --no-local <a t3code checkout> C:/p/repos/remote.git, git clone C:/p/repos/remote.git C:/p/repos/p0, set user.name and user.email, git checkout -b work; git push -u origin work.
  3. Write C:/p/home/userdata/settings.json: {"providerInstances":{"devReplay":{"displayName":"Replay (dev)","driver":"acpRegistry","config":{"source":"local","commandPath":"<node -p process.execPath>","commandArgs":["C:/p/wt/apps/server/scripts/dev-replay-agent.ts"]}}}}.
  4. In apps/server, with T3CODE_DEV_SEED=0: node src/bin.ts serve --base-dir C:/p/home --port 4800 --host 127.0.0.1 (over SSH, start it with Invoke-CimMethod Win32_Process Create). Then node src/bin.ts project add C:/p/repos/p0 --base-dir C:/p/home (repeat if the first attempt fails).
  5. Seed 100 threads: from inside the repository, run node C:/p/wt/apps/server/src/bin.ts thread start --base-dir C:/p/home --provider devReplay --model command-output C:/p/repos/p0 go in 4 parallel loops (about 30 threads a minute). Archive about 70 from the sidebar (right-click, then Archive).
  6. Pair: node src/bin.ts pair --ttl 1h --base-dir C:/p/home. Export PAIR as the printed ...pair#token=... URL with its host replaced by 127.0.0.1:4800, and PW as node_modules/.pnpm/playwright@*/node_modules/playwright.
  7. node settings.cjs unarchive 7, then node settings.cjs delete 7.

common.cjs:

const fs = require('fs');
const { chromium } = require(process.env.PW);
const NL = String.fromCharCode(10);
exports.open = async (path) => {
  const browser = await chromium.launch();
  const page = await (await browser.newContext({ viewport: { width: 1600, height: 1000 } })).newPage();
  const sent = [];
  page.on('websocket', (ws) => ws.on('framesent', (f) => {
    try { for (const line of String(f.payload).split(NL)) { if (!line) continue; const j = JSON.parse(line); if (j._tag === 'Request') sent.push({ t: Date.now(), tag: j.tag, p: JSON.stringify(j.payload).slice(0, 160) }); } } catch {}
  }));
  await page.goto(process.env.PAIR);
  await page.waitForTimeout(4000);
  const env = fs.readFileSync('C:/p/home/userdata/environment-id', 'utf8').trim();
  await page.goto('http://127.0.0.1:4800' + path.replace('ENVID', env));
  return { browser, page, sent };
};
exports.record = (tag, rec) => { fs.mkdirSync('C:/p/perf/out', { recursive: true }); fs.appendFileSync('C:/p/perf/out/' + tag + '.jsonl', JSON.stringify(rec) + NL); };
exports.reqs = (sent, a, b) => { const c = {}; for (const s of sent) if (s.t >= a && s.t <= b) c[s.tag] = (c[s.tag] || 0) + 1; return c; };
exports.seq = (sent, a, b) => sent.filter((s) => s.t >= a && s.t <= b && s.tag !== 'server.reportClientActivity').map((s) => '+' + (s.t - a) + ' ' + s.tag + ' ' + s.p);

settings.cjs (all seeded threads share one title, so it waits for the button count to drop):

const { open, record, reqs, seq } = require('./common.cjs');
(async () => {
  const action = process.argv[2]; const runs = +(process.argv[3] || 7);
  const { browser, page, sent } = await open('/settings/archived');
  const recv = [];
  page.on('websocket', (ws) => ws.on('framereceived', (f) => { const s = String(f.payload); recv.push({ t: Date.now(), n: s.length }); }));
  const label = action === 'unarchive' ? /^Unarchive / : /^Delete /;
  await page.getByRole('button', { name: label }).first().waitFor({ timeout: 60000 });
  await page.waitForTimeout(6000);
  for (let i = 0; i < runs; i++) {
    const all = page.getByRole('button', { name: label });
    const before = await all.count();
    let t0 = Date.now(); await all.first().click();
    if (action === 'delete') { const dlg = page.getByRole('alertdialog').or(page.getByRole('dialog')).last(); await dlg.waitFor(); const b = dlg.getByRole('button').last(); t0 = Date.now(); await b.click(); }
    await page.waitForFunction(([re, n]) => [...document.querySelectorAll('button[aria-label]')].filter((b) => new RegExp(re).test(b.getAttribute('aria-label'))).length < n, [label.source, before], { timeout: 20000, polling: 10 });
    const tGone = Date.now();
    await page.waitForTimeout(3500);
    const t1 = Date.now();
    const big = recv.filter((r) => r.t >= t0 && r.t <= t1 && r.n > 2048).map((r) => '+' + (r.t - t0) + ' ' + r.n);
    record(action, { run: i, start: t0 - 200, end: t1 });
    console.log(JSON.stringify({ run: i, goneMs: tGone - t0, reqs: reqs(sent, t0, t1), big }));
    console.log(seq(sent, t0 - 100, t1).join('\n'));
  }
  await browser.close();
})();

Where the time goes

  • apps/web/src/components/settings/ArchivedThreadsPanel.tsx, handleThreadAction: after unarchiveThread or confirmAndDeleteThread succeeds, it calls refreshArchivedThreads() (useArchivedThreadSnapshots().refresh in apps/web/src/lib/archivedThreadsState.ts), which runs appAtomRegistry.refresh on the snapshot atom.
  • apps/web/src/hooks/useThreadActions.ts: unarchiveThread and deleteThread already call refreshArchivedThreadsForEnvironment on success, the same atom refreshed in the same tick. Two refreshes in one tick send two requests; they are not merged.
  • packages/client-runtime/src/state/orchestration.ts, archivedShellSnapshot.refreshTrigger: the shell reports deleting an archived thread as a removal (removedAt), which refetches a third time on delete.

Why it is avoidable

The panel's own refresh asks again for what the action it just called (and, for delete, the shell trigger) already asks for. One snapshot per action gives the same final list.

What a fix has to show

The same driver before and after, on Windows:


Found by the automated Windows performance sweep on 194025e.


Found by the automated Windows performance sweep on 194025e.

Activity

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