bevy/crates
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
..
bevy_a11y Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_animation Enable clippy::undocumented_unsafe_blocks warning across the workspace (#10646) 2023-11-21 02:06:24 +00:00
bevy_app Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_asset Allow removing and reloading assets with live handles (#10785) 2023-11-29 23:32:13 +00:00
bevy_audio Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_core Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_core_pipeline Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_derive Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_diagnostic Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_dylib Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_dynamic_plugin Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_ecs Override QueryIter::fold to port Query::for_each perf gains to select Iterator combinators (#6773) 2023-12-01 09:09:55 +00:00
bevy_ecs_compile_fail_tests Override QueryIter::fold to port Query::for_each perf gains to select Iterator combinators (#6773) 2023-12-01 09:09:55 +00:00
bevy_encase_derive Add [lints] table, fix adding #![allow(clippy::type_complexity)] everywhere (#10011) 2023-11-18 20:58:48 +00:00
bevy_gilrs Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_gizmos Bind group layout entries (#10224) 2023-11-28 04:00:49 +00:00
bevy_gltf Add GltfLoaderSettings (#10804) 2023-11-30 00:34:45 +00:00
bevy_hierarchy Split WorldQuery into WorldQueryData and WorldQueryFilter (#9918) 2023-11-28 03:56:07 +00:00
bevy_input Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_internal Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_log Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_macro_utils Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_macros_compile_fail_tests Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_math Use minor and major radii for Torus primitive shape (#10643) 2023-11-21 01:49:35 +00:00
bevy_mikktspace Enable clippy::undocumented_unsafe_blocks warning across the workspace (#10646) 2023-11-21 02:06:24 +00:00
bevy_pbr Fix prepass binding issues causing crashes when not all prepass bindings are used (#10788) 2023-11-29 23:11:12 +00:00
bevy_ptr Enable clippy::undocumented_unsafe_blocks warning across the workspace (#10646) 2023-11-21 02:06:24 +00:00
bevy_reflect Fix nested generics in Reflect derive (#10791) 2023-11-29 01:46:09 +00:00
bevy_reflect_compile_fail_tests Fix nested generics in Reflect derive (#10791) 2023-11-29 01:46:09 +00:00
bevy_render try_insert Aabbs (#10801) 2023-11-29 15:00:50 +00:00
bevy_scene Mention DynamicSceneBuilder in doc comment (#10780) 2023-11-28 23:45:00 +00:00
bevy_sprite try_insert Aabbs (#10801) 2023-11-29 15:00:50 +00:00
bevy_tasks Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_text Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_time Wait until FixedUpdate can see events before dropping them (#10077) 2023-11-26 23:04:41 +00:00
bevy_transform Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_ui Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_utils Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_window Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00
bevy_winit Remove unnecessary path prefixes (#10749) 2023-11-28 23:43:40 +00:00