Reworking ComposableThreads' API
In the previous post I wrote about releasing ComposableThreads for Rust (also published on crates.io). I’ve kept improving it since, so let me lay out where that’s gone.
As I mentioned last time, while benchmarking I found that rayon’s join() was faster than I expected. At first I figured that if I just tuned the stackless (async) implementation properly, I could catch up to rayon’s performance, but it became clear there’s a limit to how far tuning async alone can get you. Thinking it through: as long as you’re building a mechanism to suspend a task synchronously, you can’t avoid the bookkeeping needed to track task state, or the branching cost of returning to the scheduler once. Async is marketed as “zero overhead,” but the cost of pulling out a continuation is unavoidable — I realized there was no catching up to rayon’s performance without changing the API itself. So I reworked the implementation to bring in rayon’s API as another model.
wendo.me