-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Naive garbage collection (Adopted) #11582
base: main
Are you sure you want to change the base?
Conversation
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.
Awesome! Could you add doc comments to all of the new methods? The ones that were already added are a good template.
Additionally it appears that the CI is failing because the internal storage of certain structs have changed. You may need to update the respective functions to reflect these changes.
/// Shrinks the backing storage for the [`BlobVec`] such that the `len == capacity`. | ||
/// | ||
/// This runs in `O(n)` time and may require reallocating backing buffer. | ||
pub fn shrink_to_fit(&mut self) { |
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.
Could you add a test to this method, since everything else seems to depend on this? Some good things to test:
- Popping items from a
BlobVec
then shrinking - Shrinking a
BlobVec
with a capacity of 0 - Shrinking a
BlobVec
with a capacity >= 1 but a length of 0
let current_layout = | ||
array_layout(&self.item_layout, self.capacity).expect("array layout should be valid"); | ||
self.data = if self.len == 0 { | ||
unsafe { |
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.
This needs a safety comment, as does the realloc below. If you need a reference, the safety comments on the allocation functions in grow_exact
should be pretty close to the ones we should use here.
@@ -323,6 +323,12 @@ impl ComponentSparseSet { | |||
} | |||
} | |||
|
|||
pub fn shrink_to_fit(&mut self) { |
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.
This should probably have a doc comment as it's actually usable outside of bevy_ecs
.
Objective
Solution