TaskPool threads should utilize CPU affinity
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## What problem does this solve or what need does it fill?
All of the platforms Bevy works on runs using a preemptive thread scheduler that will preempt and reschedule threads across multiple CPU cores.
However, by default, even if one thread is spawned for every logical CPU core, there is no guarantee that threads are assigned uniformly to every core. This can result in a thread moving from physical core to physical core without the user or programmer knowing. This comes with potential performance impact, as most modern CPUs have per-core memory cache. Moving threads not only incurs a thread preemption cost, but also potentially forces multiple cache misses.
## What solution would you like?
Allow optionally enabling CPU affinity on platforms that support it. CPU affinity forces threads to be scheduled on a specific CPU core, and will defer rescheduling the thread until the physical core becomes available again. This might slightly increase latency, but ensures that the workload is being evenly distributed among all available physical CPU cores.
Contributor guide
Assessment
This issue has not been assessed yet.