async-executor icon indicating copy to clipboard operation
async-executor copied to clipboard

Add a way to batch spawn tasks

Open notgull opened this issue 2 years ago • 4 comments

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

notgull avatar Feb 13 '24 15:02 notgull

@smol-rs/admins I would appreciate a review on this, as it's blocking performance work in Bevy.

notgull avatar Feb 22 '24 03:02 notgull

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.

taiki-e avatar Feb 22 '24 04:02 taiki-e

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.

notgull avatar Feb 22 '24 04:02 notgull

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

taiki-e avatar Feb 22 '24 04:02 taiki-e

Hmm, looks like the issue was related to the thread-optimized backend? It looks like it doesn't leak memory now.

notgull avatar Mar 30 '24 15:03 notgull