Tiny, competitive, forbid(unsafe_code), async runtime
Overview
This was more of a challenge rather than a stab at a practical use case. I understand when to use unsafe in Rust and I've written a multi-threaded async executor which uses it to decent success.
That said, still open to discussion about this simplified result. Previous iterations can be found in the branches of the repo, with a more complete version sporting timers and a tokio drop-in API in this branch.
Notable Features:
- It's about 1k LOC
- Exposes only two functions:
block_onandspawn - the IO types can be used with any runtime as they're decoupled
- Its competitive in scheduler and IO performance with tokio on both throughput and latency (run benchmarks yourself)
- The lib itself doesn't employ unbounded spinning as seen in other popular crates
Dependencies:
The executor aspect can technically be done without dependencies, but currently uses the following:
- crossbeam for faster run queue implementations (main throughput optimization)
- try-lock for basically RefCell when Sync + avoids heap alloc of std Mutex
pin_utils::pin_mutto Pin futures without heap alloc ofBox::pin- once-cell for static init of global exec & io driver. Don't know of a safe, no-dep way to do this without it
- num-cpus to query cpu count for global exec. Again, dont know any other safe way to do so without it
- mio for IO-multiplexing. Similar reasoning as num-cpus