-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
EntityMut::get_components_mut.
#20273
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
Conversation
|
I'm not sure if this is a good idea; the access checks are precisely the reason why #13375 was not merged. Adding unsafe variants in #20265 is one thing (since there is no perf cost and the user has to opt-in to using unsafe), but adding this safe API will encourage a lot of users to start using it without necessarily putting thought into the perf implications. I guess @cart should probably weigh in? |
Yeah, I won't be too surprised if this gets closed, but I think it's worth considering, and I had the code ready. :) There are plenty of cases where the perf cost won't matter, and there are users who want this functionality even with the cost. And if they wind up in a situation where the performance is a problem, they can switch to the (And for code that's really performance sensitive, you even want to avoid the |
I can understand that users may gravitate towards it purely because it's marked as safe. That said, there's no excuse for users not profiling their code and Bevy should not design its API as if users cannot be trusted to do that. Simply document it as being much slower than the unchecked version and let users decide. |
alice-i-cecile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is worth doing, even with a relatively slow implementation. It's a useful helper, and frankly, perf-sensitive code shouldn't be using this path in the first place.
…s_mut # Conflicts: # crates/bevy_ecs/src/world/entity_ref.rs
|
Closing in favor of #21780, which offers a more efficient allocation-free implementation of this API. |
Objective
Provide a simple way to get mutable access to multiple components from an
EntityMutat the cost of some performance.This is the API from #13375, but with access checks added. Cart said these checks are "dissatisfying from a perf perspective because Access allocates" in #13375 (comment). But we haven't found a more performant approach, and there are use cases where doing these checks on each call is still fast enough.
Note that unchecked variants were added in #20265.
Solution
Add
get_components_mutandinto_components_muttoEntityMutandEntityWorldMut. Have them perform the access checks by callingQueryData::update_component_accessbefore callinginto_components_mut_unchecked.