Skip to content

Every sidebar thread row re-renders twice on load on Windows because row hooks subscribe to the whole server-config map for one boolean (about 430 ms at 300 threads) #39934

Open

Description

@juliusmarminge

What is slow

On page load (or reconnect) with many threads in the sidebar, each server-config update re-renders every sidebar thread row, even though each row only needs one boolean from it. The user waits on a blocked main thread before the app responds. The cost scales with the number of rendered rows (all rows render; the list is not virtualized).

Measured

  • Windows Server 2025, 4 vCPU, 16 GB, no GPU (main-thread long tasks only).
  • Commit ccabed086a on main, production web build served by the server from source.
  • Seed: 10 projects (git repos with 20 small files) x 30 finished devReplay threads = 300 threads. Baseline 10 x 3 threads (30 rows): long-task total median 1215 ms (1020-1279).
  • Main, 300 rows, 16 loads: long-task total median 3401 ms (2198-4045), row renders median 2113. In 9 of 16 loads the server-config Map changes after the rows mount, and the probe attributes 600 row renders (2 full passes; 900 in one load) to a useSyncExternalStore hook holding a Map(1): the server-config map.
  • Scratch build where useSupportsMultiplePullRequests and useSidebarLinkedIssueState read a per-environment boolean atom instead, 18 loads on the same machine:
    • Median 2943 ms (2198-3289).
    • Server-config-driven row renders 0 in every load.
    • In the loads that had the extra passes: 3438 ms -> 3012 ms median, about 430 ms.
  • Linux, same seed: row renders 2113 -> 1513 in every load.

How to measure it again

  1. Build the web app (cd apps/web && vp build). From apps/server, start a seeding server with T3CODE_DEV_SEED=0 node src/bin.ts serve --base-dir <home> --port <p> --host 127.0.0.1 --dev-url http://localhost:5733 (registers devReplay).
  2. Seed: node seed.cjs <apps/server dir> <home> <reposDir> 10 30 4 (script below). Restart the server on the same home without --dev-url to serve the production web.
  3. Pair with node src/bin.ts pair --ttl 1h --base-dir <home> and take the http...pair#token=... URL.
  4. node probe.cjs <path to node_modules/.pnpm/playwright@*/node_modules/playwright> <pairUrl> 10 out.json. Row renders caused by the server-config map show as why keys hook<N>:Map(1); the long-task total is longTaskMs.
// seed.cjs <serverDir> <home> <reposDir> <projects> <threadsPerProject> [concurrency]
const { execFileSync, execFile } = require("node:child_process"); const fs = require("node:fs"); const path = require("node:path");
const [serverDir, home, reposDir, nP, nT, conc = "4"] = process.argv.slice(2);
const run = (a) => new Promise((res, rej) => execFile(process.execPath, ["src/bin.ts", ...a], { cwd: serverDir, env: { ...process.env, T3CODE_DEV_SEED: "0" }, maxBuffer: 1 << 26 }, (e, o, er) => e ? rej(new Error(String(er || e.message))) : res(o)));
const retry = async (a) => { try { return await run(a); } catch { return await run(a); } };
(async () => { const jobs = [];
  for (let i = 0; i < +nP; i++) { const dir = path.join(reposDir, `proj-${i}`); fs.mkdirSync(dir, { recursive: true });
    for (let f = 0; f < 20; f++) fs.writeFileSync(path.join(dir, `file${f}.txt`), `hello ${i} ${f}\n`);
    execFileSync("git", ["init", "-q", "-b", "main"], { cwd: dir }); execFileSync("git", ["add", "."], { cwd: dir });
    execFileSync("git", ["-c", "[email protected]", "-c", "user.name=seed", "commit", "-qm", "init"], { cwd: dir });
    const pid = /Added project (\S+)/.exec(await retry(["project", "add", dir, "--base-dir", home]))[1];
    for (let t = 0; t < +nT; t++) jobs.push([pid, `task ${i}-${t}`]); }
  let next = 0; await Promise.all(Array.from({ length: +conc }, async () => { while (next < jobs.length) { const [pid, m] = jobs[next++];
    await retry(["thread", "start", "--base-dir", home, "--provider", "devReplay", "--model", "todo-list", "--wait", "--json", pid, m]); } }));
  console.log("DONE", jobs.length); })();
// probe.cjs <playwrightPath> <pairUrl> <runs> <out.json>
const [pw, pairUrl, runs, out] = process.argv.slice(2); const { chromium } = require(pw); const fs = require("node:fs");
const init = () => { window.__lt = []; new PerformanceObserver((l) => { for (const e of l.getEntries()) window.__lt.push(e.duration); }).observe({ type: "longtask", buffered: true });
  window.__rows = { total: 0, why: {} }; let prev = new WeakSet();
  const isRow = (f) => { let c = f.child; for (let i = 0; i < 30 && c; i++) { if (c.tag === 5) return c.memoizedProps?.["data-thread-item"] !== undefined; c = c.child; } return false; };
  window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = { supportsFiber: true, renderers: new Map(), inject() { return 1; }, checkDCE() {}, onScheduleFiberRoot() {}, onCommitFiberUnmount() {}, onPostCommitFiberRoot() {},
    onCommitFiberRoot(_, root) { const seen = new WeakSet(); const st = [root.current];
      while (st.length) { const f = st.pop(); seen.add(f);
        if (!prev.has(f) && (f.flags & 1) && (f.tag === 14 || f.tag === 15) && isRow(f)) { window.__rows.total++; const a = f.alternate; let why;
          if (!a) why = "mount"; else { const k = Object.keys(f.memoizedProps).filter((k) => f.memoizedProps[k] !== a.memoizedProps[k]);
            if (k.length) why = "props:" + k.join(","); else { why = "state"; let h = f.memoizedState, ha = a.memoizedState, i = 0;
              while (h && ha) { if (h.memoizedState !== ha.memoizedState && h.queue?.getSnapshot) { const v = h.memoizedState; why = `hook${i}:${v?.constructor?.name}${v?.size !== undefined ? "(" + v.size + ")" : ""}`; break; } h = h.next; ha = ha.next; i++; } } }
          window.__rows.why[why] = (window.__rows.why[why] || 0) + 1; }
        if (f.sibling) st.push(f.sibling); if (f.child) st.push(f.child); }
      prev = seen; } }; };
(async () => { const b = await chromium.launch(); const ctx = await b.newContext({ viewport: { width: 1600, height: 1000 } });
  const p0 = await ctx.newPage(); await p0.goto(pairUrl); await p0.waitForTimeout(3000); await p0.close(); const origin = new URL(pairUrl).origin; const res = [];
  for (let r = 0; r < +runs; r++) { const p = await ctx.newPage(); await p.addInitScript(init); await p.goto(origin + "/"); await p.waitForTimeout(12000);
    const d = await p.evaluate(() => ({ lt: window.__lt.reduce((s, x) => s + x, 0), rows: window.__rows, items: document.querySelectorAll("[data-thread-item]").length }));
    console.log(JSON.stringify({ run: r, longTaskMs: Math.round(d.lt), rowRenders: d.rows.total, items: d.items, why: d.rows.why })); res.push(d); await p.close(); }
  fs.writeFileSync(out, JSON.stringify(res)); await b.close(); })();

Run at least 10 loads per side: in about 40% of loads the config arrives before the rows mount and neither side shows the passes. Compare the loads that do.

Where the time goes

  • apps/web/src/hooks/useSupportsMultiplePullRequests.ts (useSupportsMultiplePullRequests) and apps/web/src/state/issues.ts (useSidebarLinkedIssueState). Both are called inside the memoized SidebarThreadRow (apps/web/src/components/sidebar/SidebarThreadRow.tsx), and both call useServerConfigs(), which subscribes to the whole environmentPresentations.serverConfigsAtom Map.
  • That Map is replaced each time an environment's server config object changes, which happens twice during startup. Each replacement re-renders every row (three such hook subscriptions per row), although the values the rows derive (whether the environment has a config, whether capabilities.issues is true) do not change.
  • Probe: 600 renders per affected load at 300 rows, attributed to hook<N>:Map(1); each 300-row pass is a 200-500 ms long task on Windows.

Why it is avoidable

Each row needs one boolean per environment, which is the same before and after those updates. A subscription to that boolean would not wake the rows, and their output is unchanged.

What a fix has to show

The probe above on the 300-thread seed, before and after, on the same Windows machine, at least 10 loads each:

  • Row renders attributed to the server-config map go from 600 to 0.
  • In loads that had those passes, the median long-task total drops by about 400 ms (measured: 3438 -> 3012 ms).
  • Must stay: the first mount of 300 rows, and the separate provider-entry passes (filed separately). Rows must still re-render when an environment's issues capability or config presence actually changes.

Found by the automated Windows performance sweep on ccabed0.

Activity

  1. added a commit that references this issue on Nov 21, 2026
    4655a65
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