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

Naive garbage collection #4762

Closed
wants to merge 1 commit into from
Closed

Conversation

james7132
Copy link
Member

Objective

Right now, it's not possible to reclaim used memory from a World. Memory allocated to any BlobVec is only released after it grows beyond it's current capacity.

Solution

Implement BlobVec::shrink_to_fit and work the way up to World. World::shrink_to_fit can be quite expensive to use, so it's not automatically used anywhere. Users can use this in an exclusive system periodically or at opportune moments (i.e. a loading screen) to release the memory used in ECS storage.


Changelog

Added: World::shrink_to_fit to allow users to release any unused memory not currently used by the World's ECS storage.

@superdump
Copy link
Contributor

Is there a way to budget the compaction? So instead of making it maximally compact in a stop-the-world process, rather budget the things that take time and limit the amount of time that I’d spent in one call? Then it could be done spread across many ticks and there’s no need for big hitches to be planned.

@james7132
Copy link
Member Author

I injected a system to run a compaction after every frame (in CoreStage::Last) in the many_cubes example. This incurred a 2 ms delay when reallocating after the first frame where it allocates everything. After that it used ~100us per frame. This is clearly not meant to be the way to use this, but it does illustrate that this isn't too heavy of an operation.

Again this is a rather naive way of approaching this. Ideally, we should be able to inject per-component/per-archetype compactions when we know individual columns, sparse sets, or archetypes are not being accessed, or alternatively, if we switch to a chunk based storage, we can automatically deallocate chunks as we swap_remove away entities.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events C-Performance A change motivated by improving speed, memory usage or compile times X-Controversial There is active debate or serious implications around merging this PR labels May 16, 2022
@Weibye Weibye added the S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! label Aug 10, 2022
@james7132
Copy link
Member Author

Closing in favor of #11582.

@james7132 james7132 closed this Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible C-Performance A change motivated by improving speed, memory usage or compile times S-Adopt-Me The original PR author has no intent to complete this work. Pick me up! X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants