From 8cf06bb4a02405f423b3fc8d96e149e0767a3209 Mon Sep 17 00:00:00 2001 From: Chris Lorenzo Date: Fri, 12 Jun 2026 23:58:13 -0400 Subject: [PATCH] perf(core): drop dead 1x1 placeholder upload in the image path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WebGlCtxTexture.onLoadRequest began with a texImage2D(1x1, null) + setTextureMemUse, then — with no `await` in between — every real branch (ImageBitmap / ImageData / HTMLImageElement / Uint8Array / compressed) fully (re)uploads the texture, overwriting both. No frame can render the placeholder, and the empty-texture (`tdata === null`) branch does its own 1x1 upload. Removing it saves one texImage2D GL call + one setTextureMemUse (LRU-set mutation + threshold check) per texture upload. On the TV cost model GL calls are CPU charged into the GPU command buffer, so this is real per-upload CPU removed. Visual output is byte-identical by construction. SubTexture/RenderTexture override onLoadRequest and are unaffected. Co-Authored-By: Claude Opus 4.8 --- src/core/renderers/webgl/WebGlCtxTexture.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/renderers/webgl/WebGlCtxTexture.ts b/src/core/renderers/webgl/WebGlCtxTexture.ts index 0fcf37d..65d8b02 100644 --- a/src/core/renderers/webgl/WebGlCtxTexture.ts +++ b/src/core/renderers/webgl/WebGlCtxTexture.ts @@ -161,10 +161,11 @@ export class WebGlCtxTexture extends CoreContextTexture { ); } - // Set to a 1x1 transparent texture - glw.texImage2D(0, glw.RGBA, 1, 1, 0, glw.RGBA, glw.UNSIGNED_BYTE, null); - this.setTextureMemUse(TRANSPARENT_TEXTURE_DATA.byteLength); - + // No placeholder upload here: every branch below fully (re)uploads the + // texture before this method returns, and there is no `await` in between, + // so no frame can render an intermediate 1x1. The empty-texture case + // (`tdata === null`) does its own 1x1 upload. Uploading a throwaway 1x1 + // first would be a wasted texImage2D + setTextureMemUse per texture. let w = 0; let h = 0;