Skip to content

Warm SPA: first thread open 469 → 242 ms (−48%) by un-lazying thread detail; cold-HUD loop was 3 misses - #3

Draft
jjcm wants to merge 6 commits into
cursor/composer-large-paste-perf-1f84from
cursor/hud-cold-load-perf-6e5d
Draft

jjcm wants to merge 6 commits into
cursor/composer-large-paste-perf-1f84from
cursor/hud-cold-load-perf-6e5d

Conversation

@jjcm

@jjcm jjcm commented Aug 17, 2026 •

Copy link
Copy Markdown
Owner

Two loops against two different finish lines, both production build, headless Chromium over localhost, real bb server — not Electron, not Vite dev. Do not merge.

Headline: the warm path had a real win, and it came from reverting a Track A decision. Making the thread pane lazy sped up a metric that has since been retired and cost 227 ms on the first thread a user opens in every session. Reverting it is faster on every metric now in use.

The earlier cold-first-paint loop is unchanged below: three measured misses, no product change, and a measured ceiling for whoever picks it up.


Loop 2 (current): warm in-app navigation

Finish line

apps/app/scripts/measure-warm-nav.mjs — 1440×900, cache disabled, fresh browser profile per run, no CPU throttle, seeded DB (12 projects / 400 threads / ~120k events). Each run loads /, waits until the shell is genuinely settled (sidebar + New thread painted, root composer painted, quiet beat), then clicks — timing from the in-page mousedown until the destination content is painted:

Probe What it is
threadOpen1 Primary. First thread opened in the session.
threadOpen2 A second, different thread — per-thread work without one-time cost.
newThread Back to the root composer, Ask anything. painted.
settings A heavy non-thread view.

Every verdict is interleaved A/B, two prebuilt dists alternating round by round, n=18–30 per arm.

Warm baseline at PR HEAD

threadOpen1 469 ms, threadOpen2 213 ms, newThread 107 ms, settings 152 ms.

Attribution of the primary probe — --counters (Chromium's own counters) plus a devtools.timeline trace: of 471 ms, ~305 ms is busy main thread (script 170 ms, style recalc 82 ms across ~45 recalcs, layout 8 ms) and ~165 ms is idle, spread over 4,541 top-level tasks.

Two Track A keeps provably cannot show on this path, so they are neither credited nor blamed: no pierre/Shiki/KaTeX chunk loads at all during a thread open (the fixture's threads have no file diffs, so those islands never mount), and the plugin frontends have already booted during the settle window.

MISS — prefetch the lazy thread-pane chunk during idle

Probe baseline after Delta
threadOpen1 471.2 ms 464.5 ms −6.8 ms (−1.4%)
threadOpen2 222.1 ms 216.3 ms −5.8 ms
newThread 117.5 ms 111.8 ms −5.8 ms
settings 81.0 ms 74.2 ms −6.8 ms

Reverted. settings moved by the same −6.8 ms and the prefetch cannot touch it — the whole column is drift. At a 1.5 s idle delay the prefetch was fully inert (chunk still requested after the click); even in a deliberately settled session where it had provably run (52 scripts loaded before the probes instead of 50) it recovered ~7 ms. The chunk fetch was never the cost — it overlaps the thread's own API requests.

KEEP — thread detail is a static import again

Prefetching ruled out bytes, so the remaining suspect was the React.lazy boundary itself. A spike confirmed it (−194.7 ms); the confirming A/B on the real change, n=30 per arm:

Probe baseline after Delta
threadOpen1 469.0 ms 241.7 ms −227.3 ms (−48.5%)
threadOpen2 213.1 ms 201.8 ms −11.3 ms (−5.3%)
newThread 107.1 ms 96.7 ms −10.5 ms (−9.8%)
settings 151.8 ms 153.1 ms +1.4 ms (noise)

Cold path, n=28 per arm with measure-hud.mjs — nothing pays for it:

Cold metric baseline after Delta
HUD (sidebar + New thread painted) 416.2 ms 401.7 ms −14.5 ms (no regression)
Composer Ask anything. after click 249.5 ms 197.0 ms −52.5 ms (−21.0%)
Boot payload 1669.1 KB raw / 449.7 KB br / 26 chunks 1666.1 KB / 441.2 KB / 22 chunks −8.5 KB brotli

Why the lazy boundary was expensive

Not the ~30 ms fetch. A React.lazy suspend means the pane mounts on a Suspense retry, at transition priority, so the largest view in the app renders in sliced, yielding work instead of one pass — that is the 4,541 tasks and the ~165 ms of otherwise unexplained idle. Removing the boundary removes the sliced retry, and threadOpen2 (which never had a suspend) barely moved, exactly as that explanation predicts.

Track A reached the opposite conclusion honestly, from real data — it measured / route-ready (promptbox wrapper present) and saw −131 ms. That marker lands after the shell is already on screen, which is why it has been retired.

Tradeoffs

  • A session that never opens a thread now downloads and parses the thread view as part of the workspace route chunk (~899 KB raw back in that route's static closure). On this rig that costs nothing: cold first paint is unchanged and the cold composer is 52 ms faster, because the route wave is 22 chunks instead of 26. On a slow network those bytes are a real cost localhost cannot show — but so was the round trip they replace, and the round trip was on the interaction path while these bytes are not.
  • bundle-budget.json keeps its limits and records the 8.5 KB of recovered headroom rather than ratcheting onto 441.2 KB, which would leave the next ordinary feature nowhere to land.
  • PluginPanelView stays lazy on purpose: deep-link-only, so no ordinary navigation pays its suspend.

Next, for a future warm track (measured, not attempted)

threadOpen2 at ~202 ms is now the steady-state cost, and no single chunk dominates it: ~84 ms of style recalculation across ~45 recalcs (mounting a thread writes ~3,500 attributes, ~1,300 of them SVG path attributes for ~115 icons, plus class on ~768 elements); ~106–125 ms of script spread across react-dom render, a scroll/measure helper doing ~36 forced scrollHeight/clientHeight/clientWidth reads, and the thread view itself; and ~18 API requests in two waves. Cutting further means rendering or re-rendering less on thread mount — a product decision, not a bundling one.

Verification

  • Full @bb/app suite: 349 files, 2,778 passed, 3 skipped. Lint clean. Typecheck clean.
  • Paste keepers untouched and verified: gated paste microbenchmark passes at 128 KB / 512 KB / 1 MB.
  • KEEP_DITCH.md diff is additions only.

Loop 1 (earlier): cold load to a usable HUD — 3 misses, nothing kept

apps/app/scripts/measure-hud.mjs measures time until the sidebar and an enabled New thread control are painted, then click-to-composer. Baseline: HUD 405 ms, composer 222 ms, FCP 372 ms. The HUD is the first paint (within ~30 ms of FCP), so anything that only reorders post-paint work cannot move it.

Per-chunk marginal cost of the boot payload (each chunk's own import() with its deps already resolved): sdk/contract chunk 77 ms, domain/ui chunk 59 ms, entry 27 ms, 23 others ~40 ms — ~250 ms total. Budget: ~120 ms network, ~200 ms module evaluation, ~80 ms React render.

Ceiling: aliasing zod to a no-op chainable stub, keeping every z.object({...}) call site, is −75.4 ms (−18.0%); scoped to @bb/server-contract alone, −47.0 ms (−10.5%) plus −14.8 ms on the composer.

# Change HUD delta Verdict
1 sideEffects: false on @bb/domain + @bb/server-contract −12.0 ms (−2.9%) MISS
2 Entry's static closure as one boot chunk instead of 26 −2.3 ms (−0.6%) MISS
3 publicApiRoutes (~1,400 lines) off the client's parse path −10.8 ms (−2.5%) MISS

Attempt 2 cut the boot payload 449.7 → 407.4 KB brotli and 23 requests, which cannot show on localhost — recorded rather than landed on a metric it does not serve. (The KEEP above then reconsolidated 26 → 22 chunks for free.)

Tree-shaking cannot collect the zod cost: z.object(...) is a call the bundler cannot prove pure, so unused schemas survive even under sideEffects: false, and treeshake.manualPureFunctions: ["z"] only recovered ~7 ms because chained builders are member calls on the result. A spike that removed every static schema import from all 9 @bb/sdk area modules and the 5 eager app modules dropped ten contract modules from the boot graph and left boot eval unchanged at ~248 ms — bytes are not the cost here.

Reaching that 47 ms needs a lazy sdk/apiClient seam across ~15 files in two packages plus the app. Measured, scoped, and deliberately not attempted; per the current instructions it should not land unless a warm metric proves it, and no warm metric here points at it.

AGENT GENERATED: by Claude Opus 4.5

Open in Web Open in Cursor 

cursoragent and others added 6 commits August 17, 2026 18:59
measure-load.mjs's route-ready marker for / is the promptbox wrapper, which
appears well after the sidebar has painted, so it ranks work that happens
once the HUD is already on screen. This harness measures the wait a person
actually has: the first painted frame containing the sidebar and an enabled
New thread control, then the time from clicking it until the composer's
placeholder paints.

Markers are recorded on the frame after the DOM condition first holds, so a
number means the browser painted it. Each run gets a fresh profile and a
disabled cache.

Co-authored-by: Jacob Miller <[email protected]>
Documents the new finish line, the measured cost breakdown of the / cold
load, and why each attempt was reverted. The useful result is the ceiling:
zod schema construction is 75 ms (18%) of the cold HUD, 47 ms of it behind
@bb/server-contract, and tree-shaking cannot remove it because z.object() is
not provably pure. Also records that consolidating the 26 boot chunks cuts
42 KB brotli without moving this metric, for a network-bound track to pick
up.

Co-authored-by: Jacob Miller <[email protected]>
The cold harness answers how long until the SPA first paints. This answers the
other half of the hosted web app: with the shell already up and settled, how
long a real click takes to reach painted content — first thread open (which
pays the lazy pane chunk), a second thread open, back to the root composer,
and settings.

Probe clocks start at the in-page mousedown, and markers land on the frame
after the DOM condition holds. --counters splits each probe into script,
style-recalc and layout time from Chromium's own counters.

Co-authored-by: Jacob Miller <[email protected]>
A React.lazy boundary on the thread pane does not just add a request: the
Suspense retry renders the largest view in the app at transition priority, so
the mount is sliced across thousands of scheduler tasks. Measured on the
production build in headless Chromium with interleaved A/B, n=30 per arm, the
first thread opened in a session goes 469 -> 242 ms (-48%). Prefetching the
chunk during idle first recovered only 7 ms, which is what ruled out the bytes
and pointed at the suspend.

The cold path does not pay for it. First paint of the sidebar and New thread is
unchanged, the root composer reaches its placeholder 52 ms sooner, and the boot
payload drops 8.5 KB brotli because the route wave reconsolidates from 26
chunks to 22.

Track A made this lazy from real data, but against / route-ready, a marker that
lands after the shell is already on screen.

Co-authored-by: Jacob Miller <[email protected]>
Documents the warm finish line, the baseline, the counter/trace attribution of
the first thread open, why the idle prefetch was inert, and why the lazy
boundary itself was the cost. Also records what the two Track A keeps that
cannot show on this path (pierre/Shiki islands, plugin boot) were neither
credited nor blamed for, and what the remaining ~202 ms steady-state thread
open is made of.

Co-authored-by: Jacob Miller <[email protected]>
Also records that measure-load.mjs's route-ready marker is what led to the lazy
thread pane, so the next person reads the caveat before trusting it.

Co-authored-by: Jacob Miller <[email protected]>
@cursor cursor Bot changed the title Cold-load HUD: new finish line, measured ceiling, three misses (no product change) Warm SPA: first thread open 469 → 242 ms (−48%) by un-lazying thread detail; cold-HUD loop was 3 misses Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants