Currently, Spawner exposes a spawn method that schedules the work. On multi threaded runtimes, using Tokio, this schedules the work on any thread. The same method on single threaded runtimes, schedules it always on current thread.
We have a scenario, where a thread spawns so much work that it overwhelms the thread and creates a hotspot. What we need is to have an additional Spawner::spawn_anywhere<R>(data: ThreadAware, execute: fn(data) -> impl Future<Output = R>) method that allows to spawn a work to additional threads.
- On MT threaded runtimes, this method is basically no-op and behaves the same as
spawn method.
- On ST runtimes, this method relocates the data and calls the execution function on them.
Ideally, these changes would be introduced in a backward compatible way without adding any generics to the Spawner type and keeping it's simplicity.
Currently,
Spawnerexposes aspawnmethod that schedules the work. On multi threaded runtimes, using Tokio, this schedules the work on any thread. The same method on single threaded runtimes, schedules it always on current thread.We have a scenario, where a thread spawns so much work that it overwhelms the thread and creates a hotspot. What we need is to have an additional
Spawner::spawn_anywhere<R>(data: ThreadAware, execute: fn(data) -> impl Future<Output = R>)method that allows to spawn a work to additional threads.spawnmethod.Ideally, these changes would be introduced in a backward compatible way without adding any generics to the
Spawnertype and keeping it's simplicity.