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 Update ExactSizeIterator impl to support archetypal filters (With, Without) (#5124) 2022-06-29 02:15:28 +00:00
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 Replace many_for_each_mut with iter_many_mut. (#5402) 2022-07-30 01:38:13 +00:00
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 Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00
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 Allows conversion of mutable queries to immutable queries (#5376) 2022-07-20 01:09:45 +00:00
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 Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00
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 Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00
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 Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00
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 Assert compiler errors for compile_fail tests (#3067) 2021-11-13 22:43:19 +00:00
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 Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00
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 Make Resource trait opt-in, requiring #[derive(Resource)] V2 (#5577) 2022-08-08 21:36:35 +00:00
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 ParamSet for conflicting SystemParam:s (#2765) 2022-03-29 23:39:38 +00:00
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 Assert compiler errors for compile_fail tests (#3067) 2021-11-13 22:43:19 +00:00
system_state_get_lifetime_safety.stderr Assert compiler errors for compile_fail tests (#3067) 2021-11-13 22:43:19 +00:00
system_state_iter_lifetime_safety.rs Assert compiler errors for compile_fail tests (#3067) 2021-11-13 22:43:19 +00:00
system_state_iter_lifetime_safety.stderr Assert compiler errors for compile_fail tests (#3067) 2021-11-13 22:43:19 +00:00
system_state_iter_mut_overlap_safety.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
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