perf(ui): reuse handles vector in WebGPU custom Dispatch (#132) #148
1 changed files with 6 additions and 1 deletions
perf(ui): reuse handles vector in WebGPU custom Dispatch (#132)
UIRenderer::Dispatch built a fresh std::vector<uint32_t> with reserve on every call, paying one malloc+free per dispatch. Custom compute dispatches run per-frame, so make the vector thread_local and clear() it each call: capacity grows to the high-water mark once and is reused thereafter, eliminating the per-frame allocation churn. Behavior is identical. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
commit
cb650f965d
|
|
@ -177,7 +177,12 @@ void UIRenderer::Dispatch(GraphicsCommandBuffer /*cmd*/, const GraphicsComputeSh
|
|||
// data at the recorded offset, look up the GPU handle in the heap,
|
||||
// and assemble a list of handles in the same order the JS bridge
|
||||
// expects (matching shader.customBindings).
|
||||
std::vector<std::uint32_t> handles;
|
||||
// Reuse one vector across dispatches: custom compute runs per-frame, so a
|
||||
// fresh malloc+free each call is pure churn. thread_local keeps it valid
|
||||
// even if dispatches ever cross threads; its capacity grows to the high
|
||||
// water mark once and is reused thereafter.
|
||||
thread_local std::vector<std::uint32_t> handles;
|
||||
handles.clear();
|
||||
handles.reserve(shader.customBindings.size());
|
||||
const std::uint8_t* p = static_cast<const std::uint8_t*>(push);
|
||||
for (const auto& b : shader.customBindings) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue