From 26e5ff01fda2a5802c2e7733b7016b8473219a5b Mon Sep 17 00:00:00 2001 From: LucaP Date: Mon, 12 Oct 2026 18:34:12 +0300 Subject: [PATCH] perf: compile scene shaders off-thread before the first frame I warm the world's programs with renderer.compileAsync() at the end of the async build, with the composer's scene target bound so tone mapping and output colour space key the same programs the composer draws with, and with hidden subtrees revealed so the light count matches the frame-0 warm render. The wait is capped at 2.5 s; the warm render stays as the safety net for the post passes, texture uploads and anything a slow or extension-less driver left. Test builds report renderer.info.programs, and a browser spec pins zero program growth after frame 0. On the Intel ARL laptop the frame-0 task drops from ~1.74 s to ~0.34 s with a pixel-identical first frame; measurements in docs/overnight/compile-async-results.md. --- docs/overnight/compile-async-measure.mjs | 106 ++++++++++++++++ docs/overnight/compile-async-results.md | 152 +++++++++++++++++++++++ src/scene/post-processing.ts | 10 ++ src/scene/world/environment.ts | 45 ++++++- src/scene/world/shader-warmup.ts | 96 ++++++++++++++ tests/browser/shader-warmup.spec.ts | 55 ++++++++ tests/unit/shader-warmup.test.ts | 115 +++++++++++++++++ tests/unit/world-models.test.ts | 2 + 8 files changed, 576 insertions(+), 5 deletions(-) create mode 100644 docs/overnight/compile-async-measure.mjs create mode 100644 docs/overnight/compile-async-results.md create mode 100644 src/scene/world/shader-warmup.ts create mode 100644 tests/browser/shader-warmup.spec.ts create mode 100644 tests/unit/shader-warmup.test.ts diff --git a/docs/overnight/compile-async-measure.mjs b/docs/overnight/compile-async-measure.mjs new file mode 100644 index 0000000..a6e9a8a --- /dev/null +++ b/docs/overnight/compile-async-measure.mjs @@ -0,0 +1,106 @@ +// usage: node measure.mjs