Smart Local<Vec<T>>
system parameter
#8296
Labels
A-ECS
Entities, components, systems, and events
A-Utils
Utility functions and types
C-Feature
A new feature, making something new possible
C-Performance
A change motivated by improving speed, memory usage or compile times
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
What problem does this solve or what need does it fill?
A common design pattern in bevy is the "allocate once
Vec
".Some systems require a
Vec
to accumulate values, we want to avoid allocating or re-allocating theVec
when pushing to it. Especially, we want to avoid allocating theVec
every frame. So we store it in aLocal
,clear()
it at the start of the system and use it, without worrying for allocation.This is in fact a pattern found at least twice in the bevy codebase.
A major limitation of this pattern is burst events where
store
contains manyFoo
s one frame every minutes or so. It will clog memory for the entirety of the runtime of the application, while staying empty most of the time.Since it's a common pattern, we can legitimately worry that if this pattern is repeated enough time, we will see too much memory being sat on while not being used.
What solution would you like?
Creating a system parameter encapsulating this pattern makes it discoverable, so that people can learn and grab the low hanging fruits of optimization. It is also a good place to warn users of the potential pitfalls of such a pattern.
I see a few options:
Allocator
system param, is that even possible? lolThe text was updated successfully, but these errors were encountered: