Zero-Allocation & No Type Erasure Futures

By Vittorio Romeo

The most popular implementations of futures, including std::future, use dynamic allocation and type erasure in order to allow composition of futures into fork/join asynchronous computation graphs. While this overhead is unavoidable when the control flow of the asynchronous graph depends on run-time conditions, it is unnecessary when the "shape" of the computation graph is known at compile-time.

  • Is it possible to implement composable futures without dynamic allocation and type erasure?

  • Is it worth it?

After a brief overview of the upcoming std::experimental::future additions focused on composability, this talk answers these questions showing the train of thought behind the design and implementation of an experimental future library, step-by-step. Running time, compilation time, and generated assembly benchmarks/comparisons will be provided and analyzed.

The code covered in the talk will make use of C++17 language and library features, that will be explained throughout the presentation. The intended audience for the talk should be familiar with most C++11/14 language features and with std::future (or boost::future). Knowledge of C++17 features is helpful but not required.