perf(viewer): read the stored scene while the renderer starts
What
A snapshot reopen read the stored scene from IndexedDB, decoded it and decoded its instanced shards only after the renderer was ready. None of that needs a device. adoptCachedSceneSnapshot now starts the read and both decodes before it waits for the renderer, and adopts the moment the renderer is up. The adoption itself (batch upload, shard upload, camera fit) is unchanged. A read failure still drops the hit as corrupt.
Trade-off: when the snapshot's renderer policy turns out not to match (a changed setting), the snapshot bytes are now read and then discarded. Before, that read was skipped.
Why (pre-pixel itemisation, untimed, Pop real GPU, n=5, main 803ea549ef)
The snapshot read + decode sat after the renderer wait in every sample: Holter 429-461 ms, BWK 728-757 ms, advanced_model 369-389 ms (from the change event), right before the adoption.
Tests
apps/viewer/src/hooks/sceneSnapshotLoad.prefetch.test.ts(2, real rendererSceneon a stub device): the snapshot is read before any renderer exists and adopted once one does (fails on main); a read that fails while the renderer starts still rejects and draws nothing.- Snapshot/cache files: 93/93.
What this pair (#9826 + #9827) buys, and what it does not
Measured untimed: Pop real GPU, quiet-gated (every open at load < 6 and CPU pressure < 5), arms rotated over 5 repetitions. Base is 70ecd5a09c plus the identity hasher; the arm is base + #9826 + #9827. Medians in ms from the file pick, base -> arm:
| cell | device ready | lookup ends | first frame | interactive |
|---|---|---|---|---|
| BWK first reopen | 404 -> 286 | 457 -> 253 | 619 -> 539 | 1595 -> 1582 |
| BWK snapshot reopen | 397 -> 262 | 447 -> 260 | 602 -> 552 | 1571 -> 1582 |
| advanced_model first reopen | 272 -> 263 | 159 -> 167 | 435 -> 401 | 868 -> 839 |
| advanced_model snapshot reopen | 235 -> 233 | 160 -> 164 | 404 -> 369 | 848 -> 814 |
| Holter first reopen | 277 -> 286 | 219 -> 196 | 522 -> 512 | 1833 -> 1859 |
| Holter snapshot reopen | 266 -> 273 | 216 -> 222 | 513 -> 484 | 1829 -> 1792 |
- It is a first-pixels gain on files of 256 MB and above. On BWK the stored scene is on screen 50-80 ms sooner. Interactive does not move, so this is not a gain on the interactive goals.
- The timed verdict cell is BWK first geometry on reopens, with no regressing cell anywhere, cold included. The timed A/B is pending.
- Cold BWK, a second benefit of the yielding read: base has one main-thread long task of 187-254 ms starting 114-131 ms after the pick (reps 1-4; rep 0's early task is under 108 ms); this is the whole-file read. With the yielding read there is no early long task, and the long-task total before interactive drops from 1,240-1,302 ms to 1,009-1,047 ms. First frame and interactive on BWK cold are unchanged (1379 -> 1390, 3868 -> 3868 ms).
- One untimed Holter cold sample read 8,031 ms. It started at 18:46:35 UTC, inside the fleet watchdog pass of 18:45:29 UTC, which ran the heavy build-tree sweep and checkout reclaim. Excluding it, Holter cold is 4611 (4561-4657) on base against 4611-5147 on this arm. The timed slot starts right after a watchdog pass and lists any sample that overlaps one.
- Output: a reopen identity check against base reads match on all six cached fixtures, both sides and both reopens, on the 294df5e40a signature. With one stored snapshot byte flipped, it reads RESTORE MISMATCH everywhere. The check is being repeated with the widened #9863 signature (5e80d69c71) before this is labelled.
Status
This PR lands together with #9827. They are timed as one arm and share the verdict. mergify-trial is held until the widened identity check, the altered-snapshot control and the timed A/B pass.
š¤ Generated with Claude Code