Repository navigation
perf(metal): Use Arcs rather than copying VertexBufferMappings - #10630
Conversation
7337a3c to
2f5d839
Compare
|
The absolute count of memory allocations is not a very meaningful performance metric. Do you have measurements that provide a bit more context? e.g. measure the time for a pipeline switch (either directly, or indirectly by measuring the frame time) before and after the change? How many pipeline switches do you actually have? Can you reduce the number by making the pipelines more generic? This does look like a reasonable performance optimization, at least in the sense that the code is doing something inefficient, the proposed change looks functionally correct, and reduces the inefficiency. But I'm hesitant to make performance optimizations with an unclear or modest benefit based on the needs of one application. I also wonder whether we should eliminate this copying of stage info entirely and just store an |
|
agree about the smallness of the gains. Fixed to arc as was suggested in case it would be merged. |
Arcs rather than copying VertexBufferMappings
andyleiserson
left a comment
There was a problem hiding this comment.
Thanks for the fix.
|
@Mergifyio queue |
|
@samoylenkodmitry Mergify removed this PR from the merge queue. Reason: |
|
@Mergifyio queue |
|
@samoylenkodmitry Mergify removed this PR from the merge queue. Reason: |
|
@Mergifyio queue |
Connections
None.
Description
Every pipeline switch (
assign_frominmod.rs, called byset_render_pipeline) copies the bound pipeline's stage info into the pass state.extend_from_slicecloned eachVertexBufferMapping. Each mapping owns anattributes: Vec<AttributeMapping>, so each clone allocated a newVec. That was one allocation per vertex buffer, on every switch.Arcis used to share a reference toVertexBufferMappingbetween the pipeline andCommandState, rather than copying.The change moves the cost from every pipeline switch to pipeline creation. A frame can switch pipelines thousands of times, while each pipeline is created once.
Allocations in one frame on Metal (Apple M5), counted with a counting global allocator. The frame alternates two pipelines with 2 vertex buffers each (this data is from an earlier version of the change that copied VBM IDs, but the effect on allocations should be similar):
Testing
cargo xtask test --test wgpu-gpuon macOS 26, Apple M5 (Metal): 1128 of 1134 pass. The other 6 (naga snapshots, subgroup operations, passthrough shaders, a timestamp query) fail the same way on trunk on this machine.Squash or Rebase?
One commit.
LLM Use?
Claude wrote the change and this description. I reviewed both.
Checklist
CHANGELOG.mdentries for the user-facing effects of this change are present.