rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

Deferred mutation queries

Open MiniaczQ opened this issue 3 years ago • 3 comments

RENDERED Queries that defer mutation of certain components.

MiniaczQ avatar Jun 12 '22 04:06 MiniaczQ

"Defer mutation for better parallelism" is basically the purpose of Command. Can we unify the implementation and/or API with that?

infmagic2047 avatar Jun 12 '22 07:06 infmagic2047

I'm worried that the DeferMut can be easily confused with DerefMut.

Nilirad avatar Jun 12 '22 08:06 Nilirad

I'm worried that the DeferMut can be easily confused with DerefMut.

Yeah, we can bikeshed a better name if we decide to keep the mechanic.

"Defer mutation for better parallelism" is basically the purpose of Command. Can we unify the implementation and/or API with that?

Didn't consider Command, but yes, it seems to do exactly what is needed, assuming the mutations are batched together. In fact, I think this piece of code would do exactly that:

fn foo(
  mut commands: Commands,
  bars: Query<(Entity, Cow<Bar>)>,
) {
  for (entity, bar) in vars.iter() {
    bar.0 = 0.0; // Copy happens
    commands.entity(entity).insert(bar.to_owned()); // We (re)insert the component
  }
}

2 problems with that would be:

  • bit boilerplate-y, you need to add commands as argument
  • order of mutation, with the original idea we'd keep the order the same as system order, but if it's commands and few of those get batched, what would the order of application be?

MiniaczQ avatar Jun 12 '22 11:06 MiniaczQ

Although bit non-obvious, using Commands seems like the way to go here. I'm closing the request

MiniaczQ avatar Dec 12 '23 10:12 MiniaczQ