perf(ui): reuse handles vector in WebGPU custom Dispatch (#132) #148

Merged
catbot merged 1 commit from claude/issue-132 into master 2026-06-18 15:54:36 +02:00
Showing only changes of commit cb650f965d - Show all commits

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>
catbot 2026-06-18 13:54:09 +00:00

View file

@ -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) {