mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 22:20:20 +00:00
Make a note about the performance of Query::is_empty (#12466)
# Objective `Query::is_empty` does not mention the potential performance footgun of using it with non-archetypal filters. ## Solution Document it.
This commit is contained in:
parent
ee0fa7d1c2
commit
4b64d1d1d7
2 changed files with 16 additions and 0 deletions
|
@ -188,9 +188,17 @@ impl<D: QueryData, F: QueryFilter> QueryState<D, F> {
|
|||
|
||||
/// Checks if the query is empty for the given [`World`], where the last change and current tick are given.
|
||||
///
|
||||
/// This is equivalent to `self.iter().next().is_none()`, and thus the worst case runtime will be `O(n)`
|
||||
/// where `n` is the number of *potential* matches. This can be notably expensive for queries that rely
|
||||
/// on non-archetypal filters such as [`Added`] or [`Changed`] which must individually check each query
|
||||
/// result for a match.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If `world` does not match the one used to call `QueryState::new` for this instance.
|
||||
///
|
||||
/// [`Added`]: crate::query::Added
|
||||
/// [`Changed`]: crate::query::Changed
|
||||
#[inline]
|
||||
pub fn is_empty(&self, world: &World, last_run: Tick, this_run: Tick) -> bool {
|
||||
self.validate_world(world.id());
|
||||
|
|
|
@ -1208,6 +1208,11 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
|
|||
|
||||
/// Returns `true` if there are no query items.
|
||||
///
|
||||
/// This is equivalent to `self.iter().next().is_none()`, and thus the worst case runtime will be `O(n)`
|
||||
/// where `n` is the number of *potential* matches. This can be notably expensive for queries that rely
|
||||
/// on non-archetypal filters such as [`Added`] or [`Changed`] which must individually check each query
|
||||
/// result for a match.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// Here, the score is increased only if an entity with a `Player` component is present in the world:
|
||||
|
@ -1226,6 +1231,9 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
|
|||
/// }
|
||||
/// # bevy_ecs::system::assert_is_system(update_score_system);
|
||||
/// ```
|
||||
///
|
||||
/// [`Added`]: crate::query::Added
|
||||
/// [`Changed`]: crate::query::Changed
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
// SAFETY:
|
||||
|
|
Loading…
Reference in a new issue