From c09947c86b2a18adebec822df45b88df6ab83a91 Mon Sep 17 00:00:00 2001 From: eust-w Date: Thu, 25 Jun 2026 06:58:44 +0800 Subject: [PATCH] Defer state polling during scene load --- docs/product-readiness.md | 62 +++++++++++++++++-------------- src/main.ts | 2 +- src/preview/UniversalPreviewer.ts | 12 ++++++ 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/docs/product-readiness.md b/docs/product-readiness.md index 0d5ce71..c610604 100644 --- a/docs/product-readiness.md +++ b/docs/product-readiness.md @@ -389,6 +389,14 @@ Scene evidence: the browser event loop during load; the release gate checks `sceneBuildYieldCount` so this cannot silently regress back to one long main thread task. +- Deferred state polling during scene load: manifest state streaming starts + after the Three.js scene graph has finished constructing. This prevents the + first full `/state` payload parse and body-map merge from competing with the + large-scene asset/object build on the same browser main thread. +- Fixed-body state elision: fixed shelf and inventory bodies stay bound for + diagnostics and selection, but full-state frames do not re-apply those poses + to static roots. This avoids uploading hundreds of duplicate instanced + matrices immediately after a large scene finishes loading. - Active-state polling: after the first full state frame, large scenes poll `/state?bodies=active`. The preview merges partial active frames into the initial full body map, so fixed shelf/inventory bindings remain available @@ -427,13 +435,13 @@ Scene evidence: Bundle evidence: - JavaScript chunks: `4` -- App entry chunk: `201.83 kB raw / 52.18 kB gzip` +- App entry chunk: `202.06 kB raw / 52.24 kB gzip` - Largest JavaScript gzip chunk: `140.96 KiB / 170.00 KiB` -- Total JavaScript gzip: `215.78 KiB / 230.00 KiB` +- Total JavaScript gzip: `215.84 KiB / 230.00 KiB` - Large-scene performance mode: `large-scene`, target `45 fps`, - actual idle render rate `0.8 fps`, DPR cap observed at `1.00` in release + actual idle render rate `0.9 fps`, DPR cap observed at `1.00` in release gate, `preserveDrawingBuffer=false`, `1` explicit readback render, shadows - `off`, hover picking throttled to `32ms`, `38` empty frames + `off`, hover picking throttled to `32ms`, `255` empty frames skipped, `135` static visual nodes frozen, `568` instanced local-pose nodes elided, `59` remaining mesh clones using pre-frozen source state, `627` repeated spin scans skipped, `568` repeated @@ -445,14 +453,14 @@ Bundle evidence: bounds from `51` cached source bounds, real hover proof `hoverProxy 1` with cached bounds and `fallback 0`, with `0` camera-fit traversals, `4/84` progressive scene root batches under the computed `84` root cap and `5` - batch cap, `264` no-op loading frames + batch cap, `273` no-op loading frames suppressed during the primary load, `26` browser event-loop yields during - scene construction, active state payload `34/602` with `3` reduced frames and - `4` incremental body-map merges, - UI physics-profile cache `32/3` hit/miss, UI builder-profile cache `35/1` - hit/miss, UI text write gating `114/491` write/skip, text selector cache - `559/46` hit/miss, scratch bounds transforms `1263`, diagnostics panel - throttling `21/6` render/skip, `88/636` + scene construction, active state payload `34/602` with `2` reduced frames and + `3` incremental body-map merges, + UI physics-profile cache `30/3` hit/miss, UI builder-profile cache `33/1` + hit/miss, UI text write gating `107/521` write/skip, text selector cache + `582/46` hit/miss, scratch bounds transforms `1263`, diagnostics panel + throttling `22/5` render/skip, `88/636` hover targets over cached bounds used for bounds-only ray tests, and a stable paused backend state cache reported `manual roots 636 updates 67` with `state apply 0/skip 67`. @@ -477,8 +485,8 @@ Bundle evidence: covered after removing the persistent drawing buffer. - Body-state cache gate: `browser-body-state-cache` waits for the paused scene to use a reduced active payload and still skip unchanged active poses. The - current run passed with `state apply 4/skip 63`, `statePayload=34/602`, and - `incremental=3`. + current run passed with `state apply 0/skip 67`, `statePayload=34/602`, and + `incremental=2`. - Robot safe-pose gate: `verify-real-backend-editing` now checks `robot-safe-initial-pose`, with the latest composed scene reporting `pelvis=1.850,-0.950,0.793`, proving the default G1 starts outside the shelf @@ -515,34 +523,34 @@ Bundle evidence: Control evidence: -- Cold compose endpoint: `279ms`, `4/4` composed object bodies synced. -- Repeated compose cache: `82ms`, `cached=true`, same compose key. +- Cold compose endpoint: `264ms`, `4/4` composed object bodies synced. +- Repeated compose cache: `72ms`, `cached=true`, same compose key. - Active state endpoint: full `/state` returned `602` bodies; active - `/state?bodies=active` returned `34` bodies in `57ms`, filtered `568` fixed + `/state?bodies=active` returned `34` bodies in `59ms`, filtered `568` fixed bodies, and retained `4/4` composed dynamic bodies. -- Scene Builder UI compose: representative run `4258ms` end to end with real +- Scene Builder UI compose: representative run `3559ms` end to end with real backend diagnostics. -- Share-link restore: representative full browser restore `7194ms`. -- Config import restore: representative full browser restore `7832ms`. -- Composed object body edit: `60ms`. -- Fixed inventory edit rejection: `58ms`. +- Share-link restore: representative full browser restore `6403ms`. +- Config import restore: representative full browser restore `6894ms`. +- Composed object body edit: `47ms`. +- Fixed inventory edit rejection: `59ms`. - Dynamic composed object drop: `0.48012m`. - Static shelf anchor stability: `max drift 0.00000m` after a 2500 ms resume window. -- Resume backend state: `53ms paused=false` -- Resume visible UI state: `55ms` -- Pause backend state: `220ms paused=true` -- Pause visible UI state: `50ms` +- Resume backend state: `44ms paused=false` +- Resume visible UI state: `35ms` +- Pause backend state: `54ms paused=true` +- Pause visible UI state: `43ms` - Desktop acceptance wait: `1243ms` total, product telemetry `0ms` - Mobile acceptance wait: `277ms` total, product telemetry `0ms` - Runtime diagnostics panel: `state=http://127.0.0.1:18090/state`, `control=http://127.0.0.1:18090/control`, - `latency=响应 50 ms / 确认 50 ms / 可见 50 ms`, + `latency=响应 43 ms / 确认 43 ms / 可见 43 ms`, `acceptanceLatency=0 ms / 11-0-0`, `binding=635/636; 4/568`, `builderPhysics=已添加物体 4: 后端动态 4 / 仅视觉 0`, - `renderPerformance=large-scene; target 45 fps; actual 0.8 fps; dpr 1.00; buffer preserved false; readback renders 1; shadows off; skipped 38; hover 32ms; frozen 135 prefrozen 59 spinSkip 627; instanced 568/16/16 matrices 568 cull 16 static 16 elidedLocal 568; manual roots 636 updates 67; primitive geometries 7; mesh cache 51 sources 24/51 hit/miss retained 51g/17m; bounds cache 636 fast 627 scratch 1263 source 51 hoverProxy 1 cached 1/fallback 0 camera traversals 0; scene batches 4/84 suppressed 264 yields 26; state payload 34/602 reduced 3 incremental 4; ui cache physics 32/3 builder 35/1 text 114/491 selector 559/46 diagnostics 21/6; pick targets 88/636; state apply 0/skip 67; unchanged frames 1; released 0g/0m/0t`. + `renderPerformance=large-scene; target 45 fps; actual 0.9 fps; dpr 1.00; buffer preserved false; readback renders 1; shadows off; skipped 255; hover 32ms; frozen 135 prefrozen 59 spinSkip 627; instanced 568/16/16 matrices 568 cull 16 static 16 elidedLocal 568; manual roots 636 updates 67; primitive geometries 7; mesh cache 51 sources 24/51 hit/miss retained 51g/17m; bounds cache 636 fast 627 scratch 1263 source 51 hoverProxy 1 cached 1/fallback 0 camera traversals 0; scene batches 4/84 suppressed 273 yields 26; state payload 34/602 reduced 2 incremental 3; ui cache physics 30/3 builder 33/1 text 107/521 selector 582/46 diagnostics 22/5; pick targets 88/636; state apply 0/skip 67; unchanged frames 2; released 0g/0m/0t`. - Evidence screenshot artifacts: `builder page; share page; import page; visual-only boundary canvas; desktop canvas; debug PNG; mobile canvas` - Evidence export artifacts: diff --git a/src/main.ts b/src/main.ts index 02268b0..bb8145c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1606,8 +1606,8 @@ async function loadResolvedManifest(manifest: SceneManifest): Promise { renderJointControls(); renderActuatorControls(); renderInputAvailability(); - const stateConnect = stateClient.connect(manifest.state); await previewer.loadManifest(manifest); + const stateConnect = stateClient.connect(manifest.state); const inferredEditableObjectIds = inferDefaultEditableObjectIds(manifest, { requireBody: Boolean(controlUrl) }); previewer.setDragOptions({ editableObjectIds: inferredEditableObjectIds, diff --git a/src/preview/UniversalPreviewer.ts b/src/preview/UniversalPreviewer.ts index 3e581d4..5647835 100644 --- a/src/preview/UniversalPreviewer.ts +++ b/src/preview/UniversalPreviewer.ts @@ -383,6 +383,11 @@ export class UniversalPreviewer { if (!bound) { continue; } + if (this.shouldSkipFixedBodyState(bodyName, bound)) { + this.cacheBodyState(bodyName, bodyState); + skippedBodyStateCount += bound.length; + continue; + } if (this.isCachedBodyStateUnchanged(bodyName, bodyState)) { skippedBodyStateCount += bound.length; continue; @@ -414,6 +419,13 @@ export class UniversalPreviewer { } } + private shouldSkipFixedBodyState(bodyName: string, bound: BoundObject[]): boolean { + return !this.robotBodyNames.has(bodyName) + && !this.bodyVisualOffsets.has(bodyName) + && bound.length > 0 + && bound.every((item) => item.manifest.physics === "fixed"); + } + setDragOptions(options: DragOptions): void { this.dragOptions = { editableObjectIds: options.editableObjectIds,