Events, Commands and concurrent queues #1187
alice-i-cecile
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Commands are currently system local, i.e. point 2. in the first list isn't quite correct. And point 3 is out of date - the new As an aside, I believe is unsound - we need to check the borrow for commands (i.e. use aRefCell or Sync equivalent - maybe Mutex would be fast enough since it should only be called on thread?) since we hand out &mut T
For reasons of fn oh_dear(commands: &mut Commands, commands: &mut Commands) { /* Insert nasal demons here */ } I haven't checked that, so there might be something else going on which prevents this however. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
Events and commands have a very similar conceptual model:
As I see it, there are several things that could be improved with the current design:
Commands
is not implemented as an Event, despite its obvious similarities.Commands
andEvents
are currently handled as resources by our scheduler. This means that they follow the usual rules for read / write access and, especially in the case of commands, can seriously limit the parallelization of our systems. In 90% of use cases though, the only behavior we need is "write-to-end", which can be handled in a much more concurrent way.Commands
type to our systems is unique magic that doesn't obey the typical rules for theIntoSystem
trait / macro.Proposal
EventReader
on commands, and generally reduces their magic. Rather than using the default double-buffering events behavior, process commands at the end of each stage, then clear the whole buffer..system()
method toQuery<&C, F>
,Res<&R, F>
,Event<&E>
andEventReader<&E>. Change the idiomatic parameter to
commands: Event<&Command>` and do away with the newtype pattern for events. See Resources v2 for more thoughts in this direction.Event<T>
to run in parallel. Under the hood, this might be nicely implemented by having one copy of each type of event buffer resource per thread, then collect them all automatically viaRes
andEventReader
.Event
, call it asRes<T>
(or the mutable form) instead, which gives the existing blocking behavior back.Open Questions
Beta Was this translation helpful? Give feedback.
All reactions