Subscription-based Events (legion-like) #2287
Labels
A-ECS
Entities, components, systems, and events
C-Feature
A new feature, making something new possible
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?
Current Event system does not play well with out-of-sync readers. (systems with different FixedStep's, update on demand, etc...)
What solution would you like?
legion - like subscription based events. EventReader subscribes to EventSource. EventSource-EventReader keep track of EventData usage, and free memory after EventData was consumed.
I see 3 possible implementations. In all cases EventReader should be stored as system-local resource. EventSource can be global resource. All versions also could have
unsubscribe()
.First - EventSource does not store EventData queue, EventData copied into each EventReader queue.
Simple to implement, read-efficient, easy to make thread-safe. Memory consumption and
trigger
event processing time grows linearly with EventReader's count.Second - move each EventData in Arc, have Arc-pointers in EventReader - list.
Memory fragmentation, memory alloc/dealloc (can be solved with per EventSource memory-arena [custom Arc?]), Arc dereferencing. But
trigger
costs does not grow with EventReader's count.N.B. Since events operate on inter-system level - it could turn out that memory fragmentation is not a problem... CPU cache probably will already be clogged with iterated components data.
Third - second version variation, using intrusive linked list and intrusive Arc.
Synchronized Intrusive List may be somewhat tricky to implement. Lowest memory consumption. Reader have fixed memory consumption.
The text was updated successfully, but these errors were encountered: