perf(core): drop dead 1x1 placeholder upload in the image path#103
Merged
Conversation
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 <noreply@anthropic.com>
c5906ee to
8cf06bb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
WebGlCtxTexture.onLoadRequestbegan with atexImage2D(1×1, null)+setTextureMemUse(...), then — with noawaitin between — every real branch (ImageBitmap / ImageData / HTMLImageElement / Uint8Array / compressed) fully re-uploads the texture, overwriting both. So no frame could ever render the placeholder, and the empty-texture (tdata === null) branch already does its own 1×1 upload.Removing it saves one
texImage2DGL call + onesetTextureMemUse(LRU-set mutation + threshold check) per texture upload.Why
Per the engine's 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 — the deleted upload was always overwritten with no intervening frame.
SubTexture/RenderTextureoverrideonLoadRequestand are unaffected.Reviewer notes
tdata === nullbranch is self-sufficient. Verified there's noawaitbetween texture creation and the real upload, so no intermediate frame can observe it.createNativeCtxTexturefromtexImage2Dacross frames — it relocates ~10µs of cheap GL calls while the dominanttexImage2Dstays atomic in one frame, at the cost of +1 frame latency and state-machine complexity.Testing
tsc --buildclean.pnpm test:visual(Docker) is the belt-and-suspenders check if desired.🤖 Generated with Claude Code