Repository navigation
perf(ui): preload the chat route's boot chunks on cold loads - #160293
Conversation
HTTP/1.1 cold loads queued tiny CSS facades and discovered route boot dependencies only after the entry executed. Group measured shared and route styles, generate route preload templates from captured dynamic entries, and activate only the requested route's hints in Gateway HTML. Preserve lazy features, strict execution order, and snapshot isolation. Use the scoped per-host favicon cache for transcript hydration, including negative results. Keep all bootstrap/config scheduling and authority behavior and all avatar projection/omission behavior unchanged from main. The earlier config and avatar proposals are explicitly outside this change. Rebuilt against pinned main 2b8c65c and ran four interleaved cold/reload rounds at 0/80/200 ms RTT plus four paired 200 ms netlists: - Cold visible medians: 509 -> 474, 1767.5 -> 1245.5, 3265 -> 2744.5 ms. - 200 ms netlist medians: 89 -> 76 requests, discovery waves 6 -> 5, HTTP send groups 15 -> 12, startup 2814.5 -> 2382.5 ms, visible 3873 -> 2819 ms; first HTML discovery group 8 -> 54 resources. - Config and avatar requests remain 2 -> 2; favicon requests 5 -> 1. - Candidate warm reloads all retain one page-network response. Warm visible median differences are -3/+0.5/+2 ms; the prior 4-36.5 ms penalty did not reproduce. Warm startup sends remain 3.5-10.5 ms later, recorded separately from cached transcript visibility; no exact timing-parity claim. - Initial-entry gzip: 372395 -> 371971 B, below unchanged 372347 B limit. Complete measured route boot bytes are reported separately. Validation: 238 focused tests including restored config/credential tests, UI/core/scripts typechecks, CI oxlint wrappers, formatting, diff check, and scoped-clean P2 review. Runtime-only builds and postbuild stamps passed. Gateway test preparation initially raced runtime publication; its missing transient artifact was present after publication and the serialized run passed 128/128 without weakening checks. Full declaration emission and an in-place Gateway-update transition were not exercised.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 29, 2026, 12:29 PM ET / 16:29 UTC (Revision 10). ClawSweeper reviewWhat this changesThe branch adds route-specific preload hints for faster cold chat loads, shares chat favicon requests, and updates the Control UI build checks, tests, and documentation. Merge readiness⛔ Blocked before merge - 1 item remains Keep open: current main and the latest release lack this improvement. The PR supplies measured real-browser gains and live Gateway/UI version-skew checks that address the previous compatibility concern. This review found no definite introduced defect. Priority: P2 Review scores
Verification
How this fits togetherThe Control UI is a browser app bundled with the Gateway. Its build emits assets that the Gateway serves to browsers; the browser then fetches route code and renders the chat transcript. flowchart LR
A[Measured boot modules] --> B[Control UI build]
B --> C[Route preload templates]
C --> D[Gateway route selection]
D --> E[Browser asset requests]
E --> F[Chat transcript]
F --> G[Shared favicon requests]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +188, Tests +246, Docs +12, Other +49. Total +495 across 24 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Preserve route-limited fetching and lazy stylesheet order while landing the measured cold-load improvement through the normal exact-head validation workflow. Do we have a high-confidence way to reproduce the issue? Yes: current main lacks the route preload path, and the PR specifies a real bundled-UI cold-load comparison through a TCP delay proxy. This read-only review did not rerun the benchmark. Is this the best way to solve the issue? Yes: build-generated hints and Gateway route selection use the existing build and serving owners; the reported version-skew runs support the upgrade path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5ce29782b78f. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
…/ui-cold-load-round-trips # Conflicts: # ui/src/pages/chat/link-favicon-loader.ts
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…w#160293) * perf(ui): reduce cold-load delivery round trips HTTP/1.1 cold loads queued tiny CSS facades and discovered route boot dependencies only after the entry executed. Group measured shared and route styles, generate route preload templates from captured dynamic entries, and activate only the requested route's hints in Gateway HTML. Preserve lazy features, strict execution order, and snapshot isolation. Use the scoped per-host favicon cache for transcript hydration, including negative results. Keep all bootstrap/config scheduling and authority behavior and all avatar projection/omission behavior unchanged from main. The earlier config and avatar proposals are explicitly outside this change. Rebuilt against pinned main cc0fae4 and ran four interleaved cold/reload rounds at 0/80/200 ms RTT plus four paired 200 ms netlists: - Cold visible medians: 509 -> 474, 1767.5 -> 1245.5, 3265 -> 2744.5 ms. - 200 ms netlist medians: 89 -> 76 requests, discovery waves 6 -> 5, HTTP send groups 15 -> 12, startup 2814.5 -> 2382.5 ms, visible 3873 -> 2819 ms; first HTML discovery group 8 -> 54 resources. - Config and avatar requests remain 2 -> 2; favicon requests 5 -> 1. - Candidate warm reloads all retain one page-network response. Warm visible median differences are -3/+0.5/+2 ms; the prior 4-36.5 ms penalty did not reproduce. Warm startup sends remain 3.5-10.5 ms later, recorded separately from cached transcript visibility; no exact timing-parity claim. - Initial-entry gzip: 372395 -> 371971 B, below unchanged 372347 B limit. Complete measured route boot bytes are reported separately. Validation: 238 focused tests including restored config/credential tests, UI/core/scripts typechecks, CI oxlint wrappers, formatting, diff check, and scoped-clean P2 review. Runtime-only builds and postbuild stamps passed. Gateway test preparation initially raced runtime publication; its missing transient artifact was present after publication and the serialized run passed 128/128 without weakening checks. Full declaration emission and an in-place Gateway-update transition were not exercised. * fix(ui): keep link favicon cache as the leaf module
What Problem This Solves
Fixes: the first Control UI load after a Gateway update (or on a new browser) is slow over remote connections, because the chat route's JavaScript is discovered in several sequential waves of small requests that HTTP/1.1's six connections per host drain one round trip at a time.
User Impact
Cold loads of a chat reach the transcript sooner over remote links: at 80 ms round-trip time, median time to visible transcript falls from 1,768 to 1,246 ms (−30%); at 200 ms, from 3,265 to 2,745 ms (−16%); locally 509 → 474 ms. Warm reloads (served by the service worker) are unchanged (80 ms RTT: 356 → 356 ms). Link favicons for the same host are requested once per page instead of five times. The startup entry shrinks by 424 bytes gzip. No behavior, config, or protocol changes.
Why This Change Was Made
Measured on main through a TCP delay proxy with the bundled UI and service worker: a cold chat load made about 90 requests. After the entry evaluated, about 45 more were discovered at once and drained in about 200 ms waves (one round trip each), and more small chunks followed in dependency order;
chat.startupwent out at about 3.1 s at 200 ms RTT. Many of those requests were about 1 KB per-page CSS facade modules. Warm reloads were already fine: the service worker serves about 94 of 95 requests.ui/config/control-ui-boot-preloads.ts) emits one<template data-openclaw-route-preloads="…">per boot route (chat, new) containing modulepreload and style-preload hints for that route's boot chunks. When servingindex.html, the Gateway (src/gateway/control-ui-route-preloads.ts,control-ui.ts) activates only the requested route's template and drops the others, so the chat route's chunks are fetched in the first wave while other routes pay nothing. CSS is only preloaded; the lazy stylesheet owner keeps its cascade insertion order.css-*JS facade grouping becomes one stylesheet group per measured boot route (control-ui-chunking.ts, boot manifest generator), removing a set of tiny sequential requests while keeping genuinely lazy features lazy.scripts/check-control-ui-performance.mtsand its tests account for the route preload sets; docs updated.Kept out deliberately: deduping the pre-hello
control-ui-config.jsonrequest (its current ordering protects plugin asset grants and credential changes) and changing avatar projection (a participant-data change, not delivery).Evidence
Four interleaved rounds per build, bundled UI, TCP delay proxy; medians in ms:
chat.startupsendAt 200 ms RTT the cold request list falls from 89 to 76 requests, from 6 to 5 discovery waves, and from 15 to 12 send groups; favicon requests fall from 5 to 1. All warm reloads still make exactly one non-service-worker request.
Per-file cost (
node scripts/run-vitest.mjs <file> --maxWorkers=1local wall on a heavily loaded host / summed per-test CI time from run 36588748117):control-ui.http.test.ts169.9 s / 25.6 s (existing 128-case suite; this PR adds the route-preload cases),control-ui-performance.test.ts18.3 s / 2.6 s,control-ui-performance-base.test.ts11.4 s / 4.5 s,link-favicon-cache.test.ts4.6 s / 0.2 s,link-favicon-loader.test.ts3.1 s / 0.1 s,control-ui-chunking.test.ts3.5 s / under 0.1 s.chat-sidebar-region-hosted-tabs.test.tsonly moves a type import (0.8 s in CI). The first localcontrol-ui.http.test.tsattempt failed before any assertion on a transientdist-runtimestat during concurrent runtime publication; the serialized retry passed 128/128 with nothing weakened.Update and compatibility
No config, state, schema, protocol, or service-lifecycle change; the Gateway and the bundled UI ship together, and
index.htmlis servedno-cache(the service worker caches only hashed assets), so the served HTML always matches the running Gateway. The only cross-version surface isindex.htmltemplate handling, covered for every skew combination with a live isolated Gateway (cold chat load through the real browser, seeded synthetic sessions):<template>content is inert per the HTML spec, so nothing extra is fetched)Custom
gateway.controlUi.rootbuilds of either version therefore keep working, and an in-place update needs no migration: the first reload after the update receives the newindex.htmltogether with the new hashed assets. (Timings from these compatibility runs are not comparable to the benchmark above; they ran on a heavily loaded host without the latency proxy.)ui/config/control-ui-chunking.tsis build-time Vite/Rollup chunk grouping only:controlUiBootManifestKey()normalizes a module id to look it up in the committed boot-module list while the bundle is built. It writes no persisted, serialized, or user state, and nothing reads its output at runtime except as the hashed asset files the build emits, so there is no data model to migrate.Inherited CI failures
The failing checks on head
e9320a1(run 36588748117, tested merge2faf96f= this head + mainef1f568) are all in files this PR does not touch;security-fastpassed. Each was checked on the unmodified main baseline:ef1f568alone, replayed per file:lint-suppressions(allowlist 78 vs 77),agents/command/maintenance(missingresolvePluginMetadataSnapshotAsyncmock export),agent-command.{compaction-rotation,embedded-maintenance,live-model-switch},tts-summary.selection,session-history-worker-lifecycle,server-worker-placement-session-evidence.worker,config-model-validation.runtime,update-cli.service-authority,disk-budget.physical-usage.42431b0) with the same files or signature: the fourserver-startup-*suites (worker-free fixture launching a worker) and the Doctor config-flow/preflight suites ("OpenClaw state database read admission is closed", 469 occurrences in main's hourly jobs).doctor-model-metadata-corruption.persistence(job small-9) passes alone on the baseline and does not appear in main's hourly failures. It tripped the Doctor settlement test fixture (doctor-maintenance.settlement.test-support.ts: "cannot start or inspect native processes") when the SQLite snapshot staging worker (src/infra/sqlite-snapshot-staging-owner.ts) started under it, a cross-test isolation failure in Doctor/infra code that this PR's UI and Control UI serving changes cannot reach. Recorded here as source-qualified, not proven pre-existing.The earlier heads' failures (
subagent-registry-queued-registration,chat.reset-visible-yield,session-accessor.sqlite-prepared-admission, gateway session/publication fixtures) were fixed on main by other changes (#161197, 9e4f201, 2fc693e, and the gateway fixture sweep); theclaude-sessionsandinitial-connect-splashUI e2e failures passed repeatedly on this branch and on main locally (the splash test runs on the Vite dev server, where this PR's build-only plugin never runs).