Mentions légales du service

Skip to content
Snippets Groups Projects

Preemptive iterator

Prototype aiming to provide a simple interface to introduce preemptive iterator for asynchronous Rust programs. Its purpose is to increase reactivity of async fn spending all of it's time in a long blocking loop task by simply changing the final iterator method chains.

It provides the PreemptiveIterator trait implemented for all standard Rust types implementing core::iter::Iterator. For the moment our trait provide only fold, for_each equivalent.

Overhead measurement

There is an example in examples/overhead.rs you can try it with the following command :

cargo run --release --example overhead -- --reactivity-us 100 --n-iter 1000 --duration-us 10

The arguments are :

  • The number of iteration that you will perform.
  • Duration is the time it takes for each iteration to perform.
  • Reactivity is the targeted duration (in microseconds) between each yield_now().await inserted by our iterator.

Typical overhead values is between 0 and 2% at max for large number of iteration. The bad overhead is about 40% and happens when using few iterations (<50) with short duration tasks (< 10 μs).

TODO :

  • try_fold, try_for_each (problem: generic Try trait is unstable)
  • all, any, collect, count, lt, ge, inspect, last, max, min
  • all, any ?
  • collect, partition, unzip ?
  • count, last ?
  • ge, gt, le, lt, eq, ne ?
  • min, max, min_by, max_by, min_by_key, max_by_key ?
  • product, sum, reduce ?