Highlights
Futures-concurrency is a library prototyping async/.await
-based concurrency operations intended for inclusion in the stdlib. This effort is lead by Yosh, as part of the Rust Async WG.
Library Priorities
As part of the Rust Async WG we're working towards a proposal for a base set of "futures concurrency" operations we can add to the stdlib. This library serves as a testing ground for those APIs, enabling us to experiment separately from the stdlib. And for users of stable Rust to use the futures concurrency operators without relying on nightly.
What's change in this release over v6.0.0
is that we recognize that this library isn't just a prototype for the stdlib. It needs to be usable standalone as well. This means rather than using core::async_iter::AsyncIterator
, we opt to use the ecosystem-standard futures_core::Stream
instead. This enables this library to be used in production, enabling testing and benchmarking to take place, all while still working towards inclusion in the stdlib.
Performance
Another focus in this release has been on performance. We've added a modest suite of benchmarks to the repository, and used that to track our performance optimizations. The main performance optimization we've found is the implementation of "perfect waking". When a futures-concurrency future is woken, it now only wakes the futures which were scheduled to be woken - and no more. Together with some other optimizations this has lead to drastic performance improvements across the APIs where we've implemented it:
group v6.0.1 (prev release) v7.0.0 (curr release)
array::merge 10 1.46 4.2±0.28µs 1.00 2.9±0.05µs
array::merge 100 7.60 365.5±13.01µs 1.00 48.1±1.44µs
array::merge 1000 20.88 39.2±1.49ms 1.00 1877.5±57.35µs
vec::merge 10 1.73 4.9±0.31µs 1.00 2.9±0.05µs
vec::merge 100 8.33 360.6±3.84µs 1.00 43.3±0.80µs
vec::merge 1000 17.67 38.0±0.41ms 1.00 2.2±0.06ms
We've only implemented it for two APIs so far - but that already has shown a 30%-95% performance improvement. They're synthetic benchmarks, and probably not entirely represenative. But the fact that we're making headway in removing unnecessary wakes has knock-on effects as well. If for whatever reason there are futures in a codebase where spurious waking may be expensive (not ideal, but we've seen it happen), this will ensure that doesn't end up negatively affecting performance. Meaning depending on the scenario, the benefits here may actually show up in application performance.
Zip and Chain
We've started work on two new traits: stream::Zip
and stream::Chain
. These now exist in addition to stream::Merge
, providing control over order of execution. Unlike their stdlib Iterator
counterparts, we've chosen to expose this functionality as separate traits. Not only does that enable seamless switching between merge
, zip
, and chain
semantics. It als prevents tuple-nesting when combining more than two streams together:
let s1 = stream::repeat(0).take(5);
let s2 = stream::repeat(1).take(5);
let s3 = stream::repeat(2).take(5);
// With the `StreamExt::zip` method
let s = (s1).zip(s2).zip(s3);
while let Some(((n1, n2), n3))) = s.next().await {
assert_eq!((n1, n2, n3), (0, 1, 2));
}
// With the `Zip` trait
let s = (s1, s2, s3).zip();
while let Some((n1, n2, n3)) = s.next().await {
assert_eq!((n1, n2, n3), (0, 1, 2));
}
Support for arrays and vectors has landed, with support for tuples expected soon. This requires generating some macros like we have for merge
already, and we just haven't quite gotten around to that yet. Soon!
Changelog
Added
- Implement
stream::Merge
for tuples up to length 12 by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/19
- Implement Join for 0 and 1 length tuples by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/40
- Init zip and chain traits by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/73
Changed
- Remove IntoFuture definition by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/31
- Revert away from async traits by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/24
- Remove the custom
Stream
definition by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/35
- Format debug output by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/36
- Make implementation of
Race
for tuple fair by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/58
Fixed
- Make impl of Join for single element tuple return single elmnt tuple by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/86
Internal
- Add miri to ci by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/27
- Remove
MaybeDone
from impl Join for Vec
by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/29
- Expose tuple futures from path by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/26
- Re-export the structs by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/34
- Init bench by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/46
- Reuse inline wakers by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/51
- Implement "perfect" waking for
impl Merge for Vec
(1/2) by @eholk in https://github.com/yoshuawuyts/futures-concurrency/pull/50
- Add more benchmarks by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/52
- Fix clippy warnings by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/54
- Switch Readiness to use bitvec by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/53
- Fix bench saving by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/56
- Clippying ci by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/55
- Remove duplication of
gen_conditions
by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/59
- Use
array::from_fn
to safely create output array of MaybeUninit
by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/60
- Inline random number generator by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/61
- Streamline futures benches by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/64
- Implement "perfect" waking for
impl Merge for Vec
(2/2) by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/57
- Avoid allocation for small length in PollState tracking by @michaelwoerister in https://github.com/yoshuawuyts/futures-concurrency/pull/78
- Remove
Fuse
from impl Merge for array
by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/70
- Make
{array,vec}::race
fair by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/71
- Remove
MaybeDone
from impl Join for array
by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/72
- Inline
poll_states
and remove Fuse
for vec::merge
by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/79
- Author initial comparative benchmarks by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/80
- Push fixes from #79 by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/89
- Perfect waker for
array::Merge
by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/75
- Provide const variants of the utils/ types by @yoshuawuyts in https://github.com/yoshuawuyts/futures-concurrency/pull/81
- Hide PollState variants by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/92
- Move test channel to utils by @matheus-consoli in https://github.com/yoshuawuyts/futures-concurrency/pull/91
New Contributors
- @eholk made their first contribution in https://github.com/yoshuawuyts/futures-concurrency/pull/50
- @matheus-consoli made their first contribution in https://github.com/yoshuawuyts/futures-concurrency/pull/54
- @michaelwoerister made their first contribution in https://github.com/yoshuawuyts/futures-concurrency/pull/78
Full Changelog: https://github.com/yoshuawuyts/futures-concurrency/compare/v6.0.1...v7.0.0
Read the Documentation: https://docs.rs/futures-concurrency/7.0.0/
Source code(tar.gz)
Source code(zip)