UniformsGroup: Pool per-uniform update-range objects.#33427
Merged
Mugen87 merged 2 commits intomrdoob:devfrom Apr 21, 2026
Merged
UniformsGroup: Pool per-uniform update-range objects.#33427Mugen87 merged 2 commits intomrdoob:devfrom
Mugen87 merged 2 commits intomrdoob:devfrom
Conversation
`addUniformUpdateRange` allocated a fresh `{start, count}` object every
frame, for every uniform whose value changed. On an animated scene with
dozens of per-object uniforms this was hundreds of allocations per
frame — the single largest remaining source of sampled-heap traffic
after the earlier backend fixes.
Keep the range objects in `_updateRangeCache` across frames; mark each
as `added: false` on `clearUpdateRanges()` so the next frame pushes the
same cached object back onto `updateRanges` instead of allocating a
new one.
Measured on webgpu_backdrop_water (Inspector stripped, 10 s, 1 KB
sampling, 3-run average):
total sampled heap 97.0 KB → 66.5 KB (-31.5%)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
This was referenced Apr 20, 2026
Mugen87
reviewed
Apr 20, 2026
Reviewer feedback: the `added` flag attached to each cached range object
muddles the shape that `Buffer._updateRanges` and its downstream
consumers (WebGL/WebGPU upload paths) expect to see — a clean
`{start, count}`.
Move the "already pushed this cycle" membership into a separate
`_addedIndices` Set on the instance. The cached range objects stay a
pure `{start, count}` pair, and `start`/`count` are re-assigned from the
uniform on every `addUniformUpdateRange` call (rather than only on cache
miss), so any in-place mutation downstream — e.g. WebGL's sort/merge of
ranges — cannot leak stale state into the next frame. `clearUpdateRanges`
simplifies to clearing the Set and delegating to `super`.
No behavioral change for consumers; same pooling, cleaner contract.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mugen87
approved these changes
Apr 21, 2026
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.
Related: #33419
Description
UniformsGroup.addUniformUpdateRangeallocated a fresh{ start, count }object every frame for every uniform whose value changed. Keep the range objects in_updateRangeCacheacross frames; mark each asadded: falseinclearUpdateRanges()so the next frame pushes the same cached object ontoupdateRangesrather than allocating a new one.Before / after —
webgpu_backdrop_water, 10 s, 1 KB sampling, Inspector stripped, 3-run averageupdateNumber @ UniformsGroup.js:267(caller){ start, count }allocations per frameThis contribution is funded by Spawn