-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Freeing memory held by visible entities vector #3009
Conversation
This code seems to have been removed in the rendering rework: https://github.com/bevyengine/bevy/tree/pipelined-rendering/pipelined/bevy_render2/src/camera |
How visibility is controlled then? Cannot find anything about in in the pipelined rendering. |
According to #2535, it's not! #2861 would add it but still waiting for reviews and merge. There's still the TODO: https://github.com/bevyengine/bevy/pull/2861/files#diff-4dee68290412f102be8ef381f19aa5f435836709d962ac0207680067f5442799R181-R184 |
Should then I make another PR or change the target for this one to fix the issue in the pointed branch? |
You can either:
Sadly there's no obvious way forward... |
In I was trying to figure out the behaviour because of integer divisions and so rounding. The code that does it in this PR is: let capacity = visible_entities.value.capacity();
let reserved = capacity
.checked_div(visible_entities.value.len())
.map_or(0, |reserve| {
if reserve > 2 {
capacity / (reserve / 2)
} else {
capacity
}
});
visible_entities.value.shrink_to(reserved); I wrote some code to quickly test what the results would be for some small set of numbers:
Note that there are a lot of divide by zero cases for the |
There should be no division by zero since By the way, are big Okay, I can work on a generic solution and take a look for an existing in external crates first. Perhaps, a better approach would be a chunked vector to avoid copying on grow. Maybe with an arena allocator. Could you write me down requirements on the feature, so I can do my best from the start and not to spend our time on extra reviews? |
Good point! I forgot to add that detail into the test code. I'd defer to @cart for design requirements. :) Good suggestions by the way. |
Objective During work on #3009 I've found that not all jobs use actions-rs, and therefore, an previous version of Rust is used for them. So while compilation and other stuff can pass, checking markup and Android build may fail with compilation errors. Solution This PR adds `action-rs` for any job running cargo, and updates the edition to 2021.
@YohDeadfall can you rebase? |
Sure, will do. |
1d77c95
to
a33c85b
Compare
@alice-i-cecile, rebased and updated the code. |
@superdump @james7132 @DJMcNab, I'd like your opinions on this at some point. |
Why is this needed? VisibleEntities is reallocated every frame at the moment, due to the new extract system. |
Ideally, the solution shall be like in databases to avoid shrinking memory and do relocation too often. I guess, at least it should happen once per 30 seconds or in N frames. The best solution is to collect statistics on usage and if there are spikes, do nothing. |
@DJMcNab the systems in question are in the main app schedule I think. The checking of visibility is done in the main app before extraction. |
Ah yes, of course. Sorry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks ok.
@superdump, @cart, can it be merged? |
I'm not fully convinced that this is the best place to do this cleanup, but this is a nice incremental improvement that fixes the TODO. bors r+ |
- Freeing unused memory held by visible entities - Fixed comment style # Objective With Rust 1.56 it's possible to shrink vectors to a specified capacity. Visibility system had a comment before asking for that feature to free unused memory by a vector if its capacity is two times larger than the length. ## Solution Shrinking the vector of visible entities to the nearest power of 2 elements next to `len()`, if capacity exceeds it more than two times.
- Freeing unused memory held by visible entities - Fixed comment style # Objective With Rust 1.56 it's possible to shrink vectors to a specified capacity. Visibility system had a comment before asking for that feature to free unused memory by a vector if its capacity is two times larger than the length. ## Solution Shrinking the vector of visible entities to the nearest power of 2 elements next to `len()`, if capacity exceeds it more than two times.
Objective
With Rust 1.56 it's possible to shrink vectors to a specified capacity. Visibility system had a comment before asking for that feature to free unused memory by a vector if its capacity is two times larger than the length.
Solution
Shrinking the vector of visible entities to the nearest power of 2 elements next to
len()
, if capacity exceeds it more than two times.