Repository navigation
perf(data-gpu): fix O(all) voxel scan in physicsRenderBridge, add static-instance fast path - #209
Merged
Merged
Conversation
…e, static-instance fast path for pbrFactorRender physicsRenderBridge previously excluded voxel-tagged and already-resolved rows with a per-row `store.read`/`store.get` check inside the scan loop, so it visited every row of every matching archetype each frame - including large populations of static voxel colliders (e.g. a terrain heightfield) that were always going to be skipped anyway. Move the `voxelShapeName` / `mesh` exclusion into the archetype query itself so those rows never enter the loop (O(pending) instead of O(all)). pbrFactorRender gains an opt-in `_pbrFactorStaticInstances` resource: once a scene's drawable count stabilizes, cache the per-mesh instance buffers and bind groups and just re-issue `drawIndexed` on later frames, skipping the per-frame TRS gather and instance-buffer upload for scenes that never move or grow (e.g. baked terrain). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
physicsRenderBridgeexcluded voxel-tagged and already-resolved rows with a per-rowstore.read/store.getcheck inside the scan loop, so it visited every row of every matching archetype each frame — including large static-collider populations (e.g. a terrain heightfield) that were always skipped anyway. The exclusion now happens at the archetype-query level (exclude: ["voxelShapeName", "mesh"]), so those rows never enter the loop (O(pending) instead of O(all)).pbrFactorRendergains an opt-in_pbrFactorStaticInstancesresource: once a scene's drawable count stabilizes, cache per-mesh instance buffers/bind groups and just re-issuedrawIndexedon later frames, skipping the per-frame TRS gather + instance-buffer upload for scenes that never move or grow (e.g. baked terrain).pnpm bump).Found while profiling a 256×256 voxel terrain sample in a downstream app:
physicsRenderBridgewas costing 13-15ms/frame (the majority of CPU frame time) purely from scanning ~65k static terrain colliders it was always going to skip.Test plan
pnpm --filter @adobe/data-gpu typecheck— passes (pre-existing, unrelatedinterpolate.tserror confirmed present onmainbefore this branch too)