bevy/crates/bevy_ecs_compile_fail_tests/tests/ui
James Liu 2148518758
Override QueryIter::fold to port Query::for_each perf gains to select Iterator combinators (#6773)
# Objective
After #6547, `Query::for_each` has been capable of automatic
vectorization on certain queries, which is seeing a notable (>50% CPU
time improvements) for iteration. However, `Query::for_each` isn't
idiomatic Rust, and lacks the flexibility of iterator combinators.

Ideally, `Query::iter` and friends should be able to achieve the same
results. However, this does seem to blocked upstream
(rust-lang/rust#104914) by Rust's loop optimizations.

## Solution
This is an intermediate solution and refactor. This moves the
`Query::for_each` implementation onto the `Iterator::fold`
implementation for `QueryIter` instead. This should result in the same
automatic vectorization optimization on all `Iterator` functions that
internally use fold, including `Iterator::for_each`, `Iterator::count`,
etc.

With this, it should close the gap between the two completely.
Internally, this PR changes `Query::for_each` to use
`query.iter().for_each(..)` instead of the duplicated implementation.

Separately, the duplicate implementations of internal iteration (i.e.
`Query::par_for_each`) now use portions of the current `Query::for_each`
implementation factored out into their own functions.

This also massively cleans up our internal fragmentation of internal
iteration options, deduplicating the iteration code used in `for_each`
and `par_iter().for_each()`.

---

## Changelog
Changed: `Query::for_each`, `Query::for_each_mut`, `Query::for_each`,
and `Query::for_each_mut` have been moved to `QueryIter`'s
`Iterator::for_each` implementation, and still retains their performance
improvements over normal iteration. These APIs are deprecated in 0.13
and will be removed in 0.14.

---------

Co-authored-by: JoJoJet <21144246+JoJoJet@users.noreply.github.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2023-12-01 09:09:55 +00:00
..
entity_ref_mut_lifetime_safety.rs EntityMut: rename remove_intersection to remove and remove to take (#7810) 2023-02-26 00:09:19 +00:00
entity_ref_mut_lifetime_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
query_exact_sized_iterator_safety.rs
query_exact_sized_iterator_safety.stderr Fix CI for Rust 1.72 (#9562) 2023-08-25 12:34:24 +00:00
query_iter_combinations_mut_iterator_safety.rs
query_iter_combinations_mut_iterator_safety.stderr Split WorldQuery into WorldQueryData and WorldQueryFilter (#9918) 2023-11-28 03:56:07 +00:00
query_iter_many_mut_iterator_safety.rs
query_iter_many_mut_iterator_safety.stderr Split WorldQuery into WorldQueryData and WorldQueryFilter (#9918) 2023-11-28 03:56:07 +00:00
query_lifetime_safety.rs Override QueryIter::fold to port Query::for_each perf gains to select Iterator combinators (#6773) 2023-12-01 09:09:55 +00:00
query_lifetime_safety.stderr Override QueryIter::fold to port Query::for_each perf gains to select Iterator combinators (#6773) 2023-12-01 09:09:55 +00:00
query_to_readonly.rs
query_to_readonly.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
system_param_derive_readonly.rs Simplify trait hierarchy for SystemParam (#6865) 2022-12-11 18:34:14 +00:00
system_param_derive_readonly.stderr Split WorldQuery into WorldQueryData and WorldQueryFilter (#9918) 2023-11-28 03:56:07 +00:00
system_query_get_lifetime_safety.rs
system_query_get_lifetime_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
system_query_get_many_lifetime_safety.rs
system_query_get_many_lifetime_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
system_query_get_many_mut_lifetime_safety.rs
system_query_get_many_mut_lifetime_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
system_query_iter_lifetime_safety.rs
system_query_iter_lifetime_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
system_query_iter_many_mut_lifetime_safety.rs
system_query_iter_many_mut_lifetime_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
system_query_set_get_lifetime_safety.rs
system_query_set_get_lifetime_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
system_query_set_iter_lifetime_safety.rs
system_query_set_iter_lifetime_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
system_state_get_lifetime_safety.rs
system_state_get_lifetime_safety.stderr
system_state_iter_lifetime_safety.rs
system_state_iter_lifetime_safety.stderr
system_state_iter_mut_overlap_safety.rs
system_state_iter_mut_overlap_safety.stderr Updates for rust 1.73 (#10035) 2023-10-06 00:31:10 +00:00
world_query_derive.rs Split WorldQuery into WorldQueryData and WorldQueryFilter (#9918) 2023-11-28 03:56:07 +00:00
world_query_derive.stderr Split WorldQuery into WorldQueryData and WorldQueryFilter (#9918) 2023-11-28 03:56:07 +00:00