Add a way to batch spawn tasks
For some workloads many tasks are spawned at a time. This requires locking and unlocking the executor's inner lock every time you spawn a task. If you spawn many tasks this can be expensive.
This commit exposes a new "spawn_many" method on both types. This method allows the user to spawn an entire set of tasks at a time.
Closes #91
@smol-rs/admins I would appreciate a review on this, as it's blocking performance work in Bevy.
A common bug with *_many functions in Rust is that memory safety is violated when the iterator panics. So could you please add a Miri-compatible test for such a case? (I do not believe that this implementation violates memory safety on that case, but at least the implementation does not seem to care about cases where the iterator panics.) Otherwise it looks ok to me.
A common bug with *_many functions in Rust is that memory safety is violated when the iterator panics. So could you please add a Miri-compatible test for such a case? (I do not believe that this implementation violates memory safety on that case, but at least the implementation does not seem to care about cases where the iterator panics.) Otherwise it looks ok to me.
Added! I've also added a workaround for the mutex poisoning that shows up here.
It seems miri reported memory leaks.
error: memory leaked: alloc44788 (Rust heap, size: 120, align: 8), allocated here:
https://github.com/smol-rs/async-executor/actions/runs/7999577501/job/21847610801?pr=92
Hmm, looks like the issue was related to the thread-optimized backend? It looks like it doesn't leak memory now.