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

[Merged by Bors] - Make events reuse buffers #2850

Closed
wants to merge 1 commit into from

Conversation

TheRawMeatball
Copy link
Member

I'm really curious why this wasn't the case already...

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Sep 20, 2021
@TheRawMeatball TheRawMeatball added A-ECS Entities, components, systems, and events S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Triage This issue needs to be labelled labels Sep 20, 2021
@cart
Copy link
Member

cart commented Sep 21, 2021

At the time the thought was "garbage collection". If we clear, that means events will always use the amount of memory equal to the number of events generated on the "most active" frame. Vec::new() is allocation-free, so we only allocate when there are events on a given frame. For "uncommon events" the current approach is way better, especially if they are "burst-ey and uncommon".

However for "high volume" regular events, clearing will be way faster. This new behavior is also consistent with the rest of bevy_ecs (which is also missing "garbage collection" for cases like this), so im inclined to merge.

But I think components, component tables, and events should have some sort of "shrink capacity by half if USAGE < CAPACITY / 2 for X updates" approach. "just clearing" isn't good enough. And "reallocating per frame" is abysmal.

@TheRawMeatball
Copy link
Member Author

While I could add some heuristic for garbage collection, or expose a method for manually shrinking the vecs as much as possible, I think these would be best done later with a more cohesive vision for how similar things are handled in the rest of the ECS.

@cart
Copy link
Member

cart commented Sep 22, 2021

Yeah I do think garbage collection should be handled later (after much discussion). I'm going to merge this as I do like the consistency with the rest of bevy_ecs.

@cart
Copy link
Member

cart commented Sep 22, 2021

bors r+

bors bot pushed a commit that referenced this pull request Sep 22, 2021
I'm really curious why this wasn't the case already...
@bors bors bot changed the title Make events reuse buffers [Merged by Bors] - Make events reuse buffers Sep 22, 2021
@bors bors bot closed this Sep 22, 2021
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 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.

5 participants