bevy/crates/bevy_tasks/src
Aevyrie 831ecf030c
TaskPool: Prefer task completion over executing new tasks (#18009)
# Objective

- Systems that use the task pool, either explicitly or implicitly using
parallel queries, will often end up executing tasks from different
systems.
- This can cause random tasks to block the main or render schedule at
random, adding frame variance and increasing frame times when CPU bound.
- This profile is a common occurrence on `main`.
`propagate_parent_transforms` takes more than twice as long as it
should, blocking the main schedule for that time, because it uses `task
pool.scope`, which has decided to execute tasks from the render schedule
on the main schedule.

![image](https://github.com/user-attachments/assets/c363be40-82ce-451e-ba29-3eb4ee367e0b)


## Solution

- In task pool scope execution, prefer to check if the current task is
complete instead of ticking the executor to find new work.

## Testing

- Ran the scene viewer with tracy to look for images like the one in the
objective section.
- Things look much, much better, and I could not find any occurrences: 

![image](https://github.com/user-attachments/assets/18b79394-1a7c-49c1-820a-f5207e81bbac)

![image](https://github.com/user-attachments/assets/e7d4831d-66c3-41c1-ae2c-a624724c9965)
2025-02-26 00:08:36 +00:00
..
iter Add no_std support to bevy_tasks (#15464) 2024-12-06 02:14:54 +00:00
executor.rs bevy_tasks: Apply #[deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17089) 2025-01-02 22:42:25 +00:00
futures.rs Move futures.rs, ConditionalSend and BoxedFuture types to bevy_tasks (#16951) 2024-12-29 19:29:53 +00:00
lib.rs Upgrade to Rust Edition 2024 (#17967) 2025-02-24 03:54:47 +00:00
single_threaded_task_pool.rs Move spin to bevy_platform_support out of other crates (#17470) 2025-01-23 05:27:02 +00:00
slice.rs Remove Implicit std Prelude from no_std Crates (#17086) 2025-01-03 01:58:43 +00:00
task_pool.rs TaskPool: Prefer task completion over executing new tasks (#18009) 2025-02-26 00:08:36 +00:00
task.rs Fix no_std CI Warnings and WASM Compatibility (#17049) 2024-12-30 23:01:27 +00:00
thread_executor.rs Fix no_std CI Warnings and WASM Compatibility (#17049) 2024-12-30 23:01:27 +00:00
usages.rs Move spin to bevy_platform_support out of other crates (#17470) 2025-01-23 05:27:02 +00:00
wasm_task.rs Fix no_std CI Warnings and WASM Compatibility (#17049) 2024-12-30 23:01:27 +00:00