#iterator #thread #parallel-iterator #parallel

readahead-iterator

Readahead from an iterator on a separate thread, returning items in order and synchronously

2 releases

0.1.1 Apr 26, 2021
0.1.0 Apr 25, 2021

#807 in Concurrency

Download history 94/week @ 2023-12-06 87/week @ 2023-12-13 105/week @ 2023-12-20 169/week @ 2023-12-27 74/week @ 2024-01-03 136/week @ 2024-01-10 92/week @ 2024-01-17 71/week @ 2024-01-24 96/week @ 2024-01-31 56/week @ 2024-02-07 89/week @ 2024-02-14 224/week @ 2024-02-21 163/week @ 2024-02-28 91/week @ 2024-03-06 87/week @ 2024-03-13 92/week @ 2024-03-20

472 downloads per month
Used in 2 crates (via conserve)

MIT/Apache

8KB
68 lines

Readahead adaptor for iterators

Items are generated from the iterator in a separate thread, and returned to the caller as a regular iterator, in the same order.

This is useful when the wrapped iterator does significant work that can be parallelized with other work on the calling thread. For example, if both the iterator and its client are CPU-intensive, they utilize separate cores. Or if the iterator does blocking IO on multiple files, opening of later files can be overlapped with processing of earlier files.

Rayon offers much more powerful ways to parallelize iterators. This adaptor is useful for some simpler and complementary cases:

  • Both the producer and consumer are serial.

  • Items should be produced and consumed one at a time and in order, but production and consumption can be overlapped.

  • The work is potentially IO-bound, so a separate thread can be dedicated to this iterator, rather than using an NCPUS thread pool.

No runtime deps