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

UI materials: don't reserve in loop when enough capacity #15919

Conversation

mockersf
Copy link
Member

Objective

Solution

  • Only reserve extra memory if there's not enough
  • Only reserve the needed memory, not more

@mockersf mockersf added C-Bug An unexpected or incorrect behavior A-UI Graphical user interfaces, styles, layouts, and widgets labels Oct 15, 2024
@mockersf mockersf changed the title UI materials don't reserve in loop when enough capacity UI materials: don't reserve in loop when enough capacity Oct 15, 2024
transparent_phase
.items
.reserve(extracted_uinodes.uinodes.len());
if transparent_phase.items.capacity() < extracted_uinodes.uinodes.len() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The transparent phase items vec is shared between all the extracted UI items, not just uimaterial nodes, so this isn't quite right either. Maybe the current length of items needs to be stored before the start of the loop, then this condition could become transparent_phase.items.capacity() - initial_len < extracted.uinodes.len()?

Copy link
Member Author

@mockersf mockersf Oct 15, 2024

Choose a reason for hiding this comment

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

so it seems we have no way to know the exact size required on each transparent phase, as not all nodes may go to the same if there are several cameras

Current behaviour on main is that for each entity, it's reserving "number of entities" capacity, so this PR is still an improvement
instead of:

  • for each entity
    • ensure phase can store "number of entities" more items <- allocate for every pass through the loop
    • push to the phase

it does:

  • for each entity
    • ensure once that phase can store "number of entities" more items <- allocate once
    • push to the phase <- allocate once capacity has been reached for every pass through the loop

Copy link
Contributor

@ickshonpe ickshonpe Oct 16, 2024

Choose a reason for hiding this comment

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

Yeah that makes sense. We can merge this and look for further improvements later.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 16, 2024
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 16, 2024
Merged via the queue into bevyengine:main with commit 7495d68 Oct 16, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants