Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecesssary values Vec from DynamicUniformBuffer and DynamicStorageBuffer #8299

Merged

Conversation

james7132
Copy link
Member

@james7132 james7132 commented Apr 4, 2023

Objective

Fixes #8284. values is being pushed to separately from the actual scratch buffer in DynamicUniformBuffer::push and DynamicStorageBuffer::push. In both types, values is really only used to track the number of elements being added to the buffer, yet is causing extra allocations, size increments and excess copies.

Solution

Remove it and its remaining uses. Replace it with accesses to scratch instead.

I removed the len accessor, as it may be non-trivial to compute just from scratch. If this is still desirable to have, we can keep a len member field to track it instead of relying on scratch.

@james7132 james7132 added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times labels Apr 4, 2023
@james7132 james7132 requested a review from superdump April 4, 2023 05:53
@james7132 james7132 added the C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide label Apr 4, 2023
@james7132 james7132 added this to the 0.11 milestone Apr 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2023

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

@james7132
Copy link
Member Author

james7132 commented Apr 4, 2023

This seems to show a rough ~12% improvement over main when testing against many_cubes -- sphere (867.26us -> 761.4us) on prepare_uniform_components<MeshUniform>.

image

Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming it doesn’t break anything, and I’m sure we’d find out quickly. :) Wondering how this was missed previously. I imagine I was involved in the missing it.

@superdump superdump added this pull request to the merge queue Apr 4, 2023
Merged via the queue into bevyengine:main with commit 63d89d3 Apr 4, 2023
superdump pushed a commit that referenced this pull request Apr 4, 2023
# Objective
While working on #8299, I noticed that we're using a `capacity` field,
even though `wgpu::Buffer` exposes a `size` accessor that does the same
thing.

## Solution
Remove it from all buffer wrappers. Use `wgpu::Buffer::size` instead.
Default to 0 if no buffer has been allocated yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Performance A change motivated by improving speed, memory usage or compile times
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inefficient use of Vec::push in prepare_uniform_components function
3 participants