Repository navigation
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
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-pagemousedownuntil the destination content is painted:threadOpen1threadOpen2newThreadAsk anything.painted.settingsEvery verdict is interleaved A/B, two prebuilt dists alternating round by round, n=18–30 per arm.
Warm baseline at PR HEAD
threadOpen1469 ms,threadOpen2213 ms,newThread107 ms,settings152 ms.Attribution of the primary probe —
--counters(Chromium's own counters) plus adevtools.timelinetrace: 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
threadOpen1threadOpen2newThreadsettingsReverted.
settingsmoved 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.lazyboundary itself. A spike confirmed it (−194.7 ms); the confirming A/B on the real change, n=30 per arm:threadOpen1threadOpen2newThreadsettingsCold path, n=28 per arm with
measure-hud.mjs— nothing pays for it:Ask anything.after clickWhy the lazy boundary was expensive
Not the ~30 ms fetch. A
React.lazysuspend 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, andthreadOpen2(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
bundle-budget.jsonkeeps 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.PluginPanelViewstays lazy on purpose: deep-link-only, so no ordinary navigation pays its suspend.Next, for a future warm track (measured, not attempted)
threadOpen2at ~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, plusclasson ~768 elements); ~106–125 ms of script spread across react-dom render, a scroll/measure helper doing ~36 forcedscrollHeight/clientHeight/clientWidthreads, 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
@bb/appsuite: 349 files, 2,778 passed, 3 skipped. Lint clean. Typecheck clean.KEEP_DITCH.mddiff is additions only.Loop 1 (earlier): cold load to a usable HUD — 3 misses, nothing kept
apps/app/scripts/measure-hud.mjsmeasures 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
zodto a no-op chainable stub, keeping everyz.object({...})call site, is −75.4 ms (−18.0%); scoped to@bb/server-contractalone, −47.0 ms (−10.5%) plus −14.8 ms on the composer.sideEffects: falseon@bb/domain+@bb/server-contractpublicApiRoutes(~1,400 lines) off the client's parse pathAttempt 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 undersideEffects: false, andtreeshake.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/sdkarea 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/apiClientseam 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.