[perf] WebGPU metadata flush uploads full 256 KB padded buffer every frame (RenderingElement3D-WebGPU.cpp) #130

Closed
opened 2026-06-17 21:18:55 +02:00 by jorijnvdgraaf · 0 comments

Found by an adversarially-verified performance audit (confirmed real after a skeptic pass).

Location: implementations/Crafter.Graphics-RenderingElement3D-WebGPU.cpp:162
Severity: medium · Effort: trivial · Category: memory

Problem

The metadata buffer is fixed at kNPadded = 65536 slots; only primitiveCount entries are live, but metadataBuffer.FlushDevice() wgpuWriteBuffers all 256 KB through the WASM→JS staging path every frame (~100-250× waste for a few-hundred-instance scene). The Vulkan parallel sizes to primitiveCount, so this is WebGPU-specific.

Fix

FlushDeviceRange(0, 0, primitiveCount * sizeof(uint32_t)) — the existing overload that the instanceBuffer loop directly above already uses.

Found by an adversarially-verified performance audit (confirmed real after a skeptic pass). **Location:** `implementations/Crafter.Graphics-RenderingElement3D-WebGPU.cpp:162` **Severity:** medium · **Effort:** trivial · **Category:** memory ### Problem The metadata buffer is fixed at `kNPadded = 65536` slots; only `primitiveCount` entries are live, but `metadataBuffer.FlushDevice()` `wgpuWriteBuffer`s all 256 KB through the WASM→JS staging path every frame (~100-250× waste for a few-hundred-instance scene). The Vulkan parallel sizes to `primitiveCount`, so this is WebGPU-specific. ### Fix `FlushDeviceRange(0, 0, primitiveCount * sizeof(uint32_t))` — the existing overload that the instanceBuffer loop directly above already uses.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Catcrafts/Crafter.Graphics#130
No description provided.