perf(viewer): request the renderer's WebGPU device at the file pick
Status: draft. Not timed until cold loads are neutral (see "Cold concern").
What
On a fresh page the viewport mounts during a load's interface reset, and its renderer only asked for a WebGPU device then. This PR starts the request at the file pick:
prerequestRendererDevice()(packages/renderer/src/device-request.ts) requests the adapter. It returns a promise that resolves oncerequestDeviceis in flight, or after 50 ms at most.loadFileawaits that promise once, after it owns its load session and before the reset. Without that turn the adapter's promise could only resolve after the reset's long task, sorequestDevicewent out late. Measured below; the first version of this PR had exactly that problem.- The next
WebGPUDevice.init()adopts the device. - A device that is lost or fails before then is replaced by a fresh request, and a device no renderer claims within 15 s is destroyed. Nothing is requested at idle.
Measured (untimed, Pop real GPU, ABBA x5, every open quiet-gated at load < 6 and CPU pressure < 5; base 70ecd5a09c vs this PR b99da9edf0)
Medians in ms from the file input's change event (base / this PR):
| cell | requestDevice sent | reset ends | device ready | first frame | interactive |
|---|---|---|---|---|---|
| Holter snapshot reopen | 116 / 15 | 107 / 110 | 266 / 148 | 506 / 432 | 1834 / 1723 |
| Holter first reopen | 114 / 15 | 105 / 111 | 268 / 176 | 515 / 424 | 1838 / 1733 |
| advanced_model snapshot reopen | 121 / 13 | 111 / 116 | 230 / 128 | 409 / 310 | 854 / 764 |
| advanced_model first reopen | 117 / 12 | 107 / 110 | 273 / 157 | 445 / 327 | 893 / 785 |
| BWK snapshot reopen | 115 / 14 | 106 / 113 | 402 / 399 | 612 / 608 | 1590 / 1572 |
| BWK first reopen | 115 / 13 | 107 / 113 | 401 / 401 | 612 / 611 | 1582 / 1584 |
| Holter cold | 123 / 14 | 114 / 117 | 292 / 127 | 1040 / 1042 | 4677 / 4617 |
| BWK cold | 114 / 13 | 106 / 118 | 390 / 127 | 1360 / 1372 | 3952 / 3910 |
| advanced_model cold | 119 / 16 | 111 / 116 | 234 / 124 | 562 / 617 | 1809 / 1841 |
| FZK cold | 119 / 16 | 111 / 117 | 233 / 126 | 336 / 364 | 574 / 617 |
- The device is ready 3-15 ms after the reset ends, 100-260 ms earlier than base. The yield costs about 3-12 ms before the reset starts.
- Holter and advanced_model reopens gain about 75-120 ms to first frame and about 90-110 ms to interactive.
- BWK reopens do not move: the device is ready at about 400 ms on both sides. That is being investigated.
Cold concern (blocks timing)
advanced_model cold is +55 ms to first frame. FZK cold is +28 ms to first frame and +43 ms to interactive. Base and PR ranges do not overlap. Next step: sourcemapped traces of the cold path, then hold renderer setup back to base's point on a cold path (or gate the request by cache size tier if the request itself costs). The itemisation is repeated afterwards.
Tests
-
packages/renderer/src/device-request.test.ts:- init adopts the early device;
- a lost or failed early device is replaced, and a lost one that throws on destroy still lets init proceed;
- an unclaimed device is destroyed after the hold, and a failure frees the slot;
- the promise resolves only once
requestDeviceis in flight; - one early request at a time, none without WebGPU.
The renderer suite passes (24/24 in the device tests).
-
apps/viewer/src/hooks/useIfcLoader.earlyDevice.test.tsx: the real hook issues requestAdapter, then requestDevice, then the reset, in that exact order (fails without the await); a renderer initialised afterwards adopts that device; nothing early when a renderer is already mounted.
š¤ Generated with Claude Code