smol-rs/async-task

Custom allocators

Opened this issue · 3 comments

I've been working on a specialized fork of async_executor focused on prioritized execution high performance CPU bound tasks for bevy. Thus far I've made a number of optimizations that definitely have helped out with overhead, but spawning tasks remains one of the primary bottlenecks, which is coming from spawn_unchecked.

One of the primary use cases is a lifetime limited scoped batch of tasks that we know the inner tasks cannot outlive. As we know that futures and tasks cannot outlive the scope, one of the more appealing options is to use bumpalo or some thread safe wrapper around it to speed up allocation.

It'd be super helpful to be able to provide a version of the API that allows specifying your own allocator or a callback for allocating memory for use in non-nightly environments.

Has there been any high-level work to integrate custom allocators into other crates in the Rust ecosystem? I support this idea in theory, but I think some finesse will be needed in practice to ensure it works with past, present and future Rust versions.

Has there been any high-level work to integrate custom allocators into other crates in the Rust ecosystem? I support this idea in theory, but I think some finesse will be needed in practice to ensure it works with past, present and future Rust versions.

Generally, outside of the std lib and a bunch of low level crates, no. The standard allocators API is not stablized yet. I wouldn't mind a TaskSpawner type that just wraps an allocator impl, and should be flexible enough that it'd be easy to migrate once a more standardized option becomes available.

I'm afraid that, if we decide to commit to an API design, and the ecosystem as a whole moves onto a different API (or if the allocator API becomes stable), we'll be forced to either stay with the old API and alienate new users, or make a breaking change and alienate old ones. Although I'm a fan of this idea, I'd hold off on it until the ecosystem makes a move in one direction of the other.