Skip to content

Reduce composer startup waits and warm optional SDK renderers - #6295

Merged
ymichael merged 1 commit into
mainfrom
bb/optimize-mobile-composer-load-time-thr_ab9uvre7ft
Oct 26, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/optimize-mobile-composer-load-time-thr_ab9uvre7ft

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

On cold new-thread and thread loads, essential plugin assets were discovered after the plugin runtime loaded, and activation waited for the toaster to mount. The SDK also eagerly imported Markdown and the diff/source adapters even when the page only needed a composer. Delaying the toaster module by 2.5 seconds reproduced a visible composer skeleton on the previous build.

What changed

  • Start essential plugin boot when system config resolves and preload priority plugin JavaScript/CSS alongside the runtime using the shared plugin-list query.
  • Remove the toaster activation gate. Queue normal, raw, and custom startup notifications until attachment; honor dismissals before attachment.
  • Split the SDK Markdown, diff, and source components and warm them through the existing idle queue. After plugin registration, warm selected built-in renderers; skip those built-ins when a plugin replacement is selected.
  • Start selected built-in diff/source imports and worker requests alongside SDK adapter loading; apply the same early loading to timeline diffs. Idle warming does not initialize workers.
  • Document the lazy-loading audit and add regression coverage for the existing parallel route preloads. Route code and thread bootstrap/timeline loading were already parallel; this PR does not introduce a new route preparation layer.

Existing renderer-selection and worker-readiness boundaries remain. Shared Pierre bindings stay eager for plugin compatibility. Content-dependent Markdown loading still has a possible cold-path waterfall, and the existing idle queue still drains its warmups together. No public SDK contract, CLI, or server/daemon wire fields change.

How you verified

  • pnpm exec turbo run lint typecheck build --filter=@bb/app passed (existing lint and build warnings remain).
  • 53 focused tests across plugin startup, notification startup, SDK Markdown links, cold renderer ordering, renderer replacements and skeletons, idle warming, route preloads, and bundle budgets passed. The additional thread-query and route suite passed 31 tests.
  • Mutation checks: removing early renderer loads fails the cold-load regression; removing the existing route-preload effects fails the route regression. The priority-plugin startup and queued-toast regressions were also checked against their previous implementations.
  • Ran pnpm start:worktree; used the source BB CLI against its isolated server to inspect the thread, machines, and essential plugins. Used bb browser-automation to check new and existing threads at 1440×1000 and 390×844 in light mode, capturing 16 before/after screenshots against a separately built committed baseline using the same server data.
  • With toaster code delayed, the baseline had no editable composer at capture time; this branch had one on both routes at both sizes. Fully loaded layouts remained stable, with no visible error alerts.
  • Cold-cache mobile emulation at 2 Mbps down, 1 Mbps up, 100 ms latency, and 4× CPU slowdown: typed and cleared unsent drafts on both routes. No provider run was started. These were single-run smoke checks, not a comparative benchmark; physical iOS Safari was not tested.

Temporary verification server: https://ymichael--19376.getbb.app/ (requires the owner's BB Connect access).

AGENT GENERATED

@ymichael
ymichael merged commit ef3956d into main Oct 26, 2026
51 checks passed
@ymichael
ymichael deleted the bb/optimize-mobile-composer-load-time-thr_ab9uvre7ft branch October 26, 2026 16:56
ymichael added a commit that referenced this pull request Oct 26, 2026
## Human comments

## What was wrong

Every plugin frontend waited for the shared Pierre diff engine and
syntax-highlighting dependencies, even when it never imported them. This
put optional renderer code on the startup path for essential plugins
such as the composer and sidebar.

## What changed

Rebased onto origin/main after #6295 merged; this PR reuses its lazy SDK
renderer components.

Plugin builds record their shared runtime dependencies in
`app.meta.json` as `runtimeSlots`. The server validates and returns
those slots. Before evaluating a plugin, a generic registry loads the
required lazy groups in parallel while preloading the plugin bundle.
Each group uses a cached, retryable loader; Pierre's core and React
bindings are the first group. Each plugin bundle URL is preloaded once,
whether the boot hook, the download-ahead step, or the lazy-runtime path
asks first.

Older artifacts without metadata remain compatible by receiving all
runtime slots. Such bundles can still trigger unnecessary Pierre
downloads, so mixed installations may see smaller download savings. The
normal bundled-plugin build emits the new metadata; no rebuild migration
or compiled-bundle inference is introduced.

The app's bundle budget adds a PluginFrontend closure that forbids
Pierre and Shiki, with limits 25% above its measured 528.9 KB raw /
165.3 KB brotli. Documentation describes the runtime dependency contract
and its distinction from render-time SDK component splitting. No
server/daemon wire change or public SDK member is introduced. The new
response field changes bundled SDK declarations; main's unpublished
0.6.81 bump (#6308) covers it, so this PR does not bump the SDK version
again. If 0.6.81 is published before this merges, it needs a new bump.

## How you verified

- Production bundle-budget check on the rebased branch passes:
PluginFrontend closure is 528.9 KB raw / 165.0 KB brotli beyond the boot
payload against the new 661.1 KB / 206.6 KB limits, with Pierre/Shiki
excluded. These are combined results with #6295, not an isolated speedup
measurement.
- Plugin builder suite (13 tests) covers recorded `runtimeSlots`; server
artifact suite (13) covers validation and the legacy all-slots fallback;
CLI plugin-build suite (9) covers metadata output.
- App plugin loading, retry, reload, load-order, boot, cold-renderer and
bundle-budget tests pass (97 across the touched files).
- Typecheck for app, server, plugin-build, CLI and demo-server passes;
app and plugin-build lint pass.
- Plugin SDK npm version guard passes (0.6.81 is not yet on npm).
- `pnpm exec turbo run prepare:bundled --filter=bb-plugin-bb--composer`
passed earlier; its emitted artifact lists `runtimeSlots` without
Pierre. No new browser timing measurements were taken for this PR.

> AGENT GENERATED

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Oct 26, 2026
)

## Human comments

## What was wrong

The plugin boot hook waited for system config before requesting the
runtime and plugin list. Another route consumer already fetched the
plugin list early; the measured route-level wait was the runtime
download. Existing-thread execution defaults and queue data waited for
bootstrap and the prompt-area module, while new-thread unscoped provider
catalogs waited for the composer module. These requests already have
enough scope to start earlier.

Rebased onto origin/main at cf8f870, which includes #6304 and #6295.
This PR preserves their lazy runtime groups, priority bundle preloads,
and existing route preparation.

## What changed

- Download the plugin runtime and list alongside config; keep frontend
activation gated on config.
- Observe defaults and queue alongside the existing thread bootstrap.
Late consumers share the active query baseline; reopening refreshes
stale data. Preserve realtime invalidation, queue focus refresh, and
sending gates.
- Prefetch unscoped environment/machine catalogs in the existing
new-thread route effect using canonical query options. Keep
project/provider/environment-dependent work scoped to known selections.
- Update `docs/ui-code-splitting.md` with observed request order and the
separate onboarding gate consideration. No wire or public CLI/SDK
changes in this PR. The SDK version bump and CLI metadata fixes are
already in main.

## How you verified

After rebasing onto cf8f870: 43 focused startup/query tests pass
across five files; app lint/typecheck, production rebuild, and bundle
budgets pass. Restarted the isolated review server and confirmed
server/daemon health and the existing scheduled fixture through the
source BB CLI. The measurements and full-suite results below were
collected before this rebase.

- `pnpm exec turbo run test lint typecheck --filter=@bb/app`:
lint/typecheck passed; all 6,315 assertions passed, but the initial full
run reported two Sonner teardown errors in unchanged
`AppToaster.test.tsx`. Focused rerun including that file passed (82
tests), then `pnpm exec turbo run test --filter=@bb/app` passed all 651
files / 6,315 tests without errors.
- Regression negative controls: restoring the prior
config/route/bootstrap gates fails each corresponding test. Reverting
the mount policy fails with two fetches instead of one. Tests cover
unresolved prerequisites, disabled routes, late consumers, invalidation,
and reopening.
- Production build through `pnpm start:worktree --dryrun` and `pnpm
start:worktree`; `node apps/app/scripts/check-bundle-budget.mjs` passes.
Brotli closures: boot 381.0 KiB, PluginFrontend 162.1 KiB beyond boot,
ThreadPage 450.0 KiB, NewThreadPage 219.8 KiB. These are bundle sizes,
not timing benchmarks.
- Real Chromium requests against a fresh isolated store, HTTP cache
disabled, storage cleared except `bb.onboarding.seen=1`, 390×844
viewport. Held config and destination module requests, plus bootstrap on
the existing route, until approximately 2.6 seconds. New-thread catalogs
started at 105 ms, list/runtime at 106 ms. Existing-thread
defaults/queue started at 116 ms, bootstrap/list/runtime at 117 ms. Each
relevant data request occurred once through composer mounting after
release. Both composers rendered; the synthetic scheduled thread
displayed its queue. No provider turns started. Browser/server stopped
and marked data removed.
- Separate cold run without the recognized onboarding preference
confirms routes still wait for config while plugin list/runtime download
independently. Onboarding policy is deferred; this is request-order
evidence under artificial holds, not a performance measurement or iOS
Safari validation. Verification inventory also reports an unrelated
pre-existing unmapped `diagnostics` CLI family.

- Direct baseline (`612383411c`) versus follow-up under the same
~2.6-second prerequisite hold: new-thread runtime 2,616 → 106 ms;
existing-thread runtime 2,607 → 117 ms; new-thread catalogs 2,932 → 105
ms; existing-thread defaults/queue 2,945 → 116 ms. Baseline plugin-list
requests were already early (124/123 ms), so no measured benefit is
claimed for that request. This demonstrates overlap under an artificial
hold, not ordinary page-load savings.
- Same-toolchain Brotli bundle comparison: boot 378.2 → 381.0 KiB;
PluginFrontend beyond boot 165.2 → 162.1 KiB; ThreadPage 452.7 → 450.0
KiB; NewThreadPage 223.0 → 219.8 KiB. Closures overlap; do not add their
differences.


> AGENT GENERATED
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.

1 participant