Parallel iterator processing library for Rust

Overview

Parallel iterator processing library for Rust

I keep needing one, so I wrote it.

See [IteratorExt] for supported operations.

In essence, if you have:

# fn step_a(x: usize) -> usize {
#   x * 7
# }
# 
# fn filter_b(x: &usize) -> bool {
#   x % 2 == 0
# }
# 
# fn step_c(x: usize) -> usize {
#   x + 1
# }
assert_eq!(
  (0..10)
    .map(step_a)
    .filter(filter_b)
    .map(step_c).collect::<Vec<_>>(),
    vec![1, 15, 29, 43, 57]
);

You can change it to:

use dpc_pariter::IteratorExt;
# fn step_a(x: usize) -> usize {
#   x * 7
# }
# 
# fn filter_b(x: &usize) -> bool {
#   x % 2 == 0
# }
# 
# fn step_c(x: usize) -> usize {
#   x + 1
# }
assert_eq!(
  (0..10)
    .map(step_a)
    .filter(filter_b)
    .parallel_map(step_c).collect::<Vec<_>>(),
    vec![1, 15, 29, 43, 57]
);

and it will run faster (conditions apply), because step_c will run in parallel on multiple-threads.

Notable features

  • order preserving
  • lazy, somewhat like a normal iterators
  • panic propagation
  • backpressure control
  • custom thread-pool support
  • other knobs to control performance & resource utilization

When to use and alternatives

This library is a good general purpose solution. When you have a chain of iterator steps, and would like to process one or some of them in parallel to speed it up, this should be a drop-in replacement.

Sending iterator items through channels is fast, but not free. Make sure to parallelize operations that are heavy enough to justify overhead of sending data through channels. E.g. operations involving IO or some CPU-heavy computation.

When you have a lot items already stored in a collection, that you want to "roll over and perform some mass computation" you probably want to use rayon instead. It's a library optimized for parallelizing processing of whole chunks of larger set of data. Because of that converting rayon's iterators back to ordered sequencial iterator is non-trivial.

There are alternative libraries somewhat like this, but I did not find any that I'd like API and/or implementation wise, so I wrote my own.

Status & plans

I keep needing this exact functionality, so I've cleaned up my ad-hoc code and put it in a proper library. I would actually prefer if someone else did it. :D I might add more features in the future, and I am happy to accept PRs.

I'm open to share ownership & maintenance, or even "donate it".

You might also like...
Performs distributed command execution, written in Rust w/ Tokio

Concurr: Distributed and Concurrent Command Execution, in Rust This project is dual licensed under MIT and Apache 2.0. Originally inspired by the GNU

🔮 Futuristic take on hexdump, made in Rust.
🔮 Futuristic take on hexdump, made in Rust.

hex (hx) Futuristic take on hexdump. hx accepts a file path as input and outputs a hexadecimal colorized view to stdout. $ hx tests/files/alphanumeric

Cross-platform Rust rewrite of the GNU coreutils

uutils coreutils uutils is an attempt at writing universal (as in cross-platform) CLI utilities in Rust. This repository is intended to aggregate GNU

A TUI system monitor written in Rust
A TUI system monitor written in Rust

NO LONGER MAINTAINED. For a similar program, check out https://github.com/ClementTsang/bottom. ytop Another TUI based system monitor, this time in Rus

A rust layered configuration loader with zero-boilerplate configuration management.

salak A layered configuration loader with zero-boilerplate configuration management. About Features Placeholder Key Convension Cargo Features Default

Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux.

Untrusted IPC with maximum performance and minimum latency. On Rust, on Linux. When is this Rust crate useful? Performance or latency is crucial, and

An over-engineered rewrite of pipes.sh in Rust
An over-engineered rewrite of pipes.sh in Rust

pipes-rs An over-engineered rewrite of pipes.sh in Rust Installlation macOS Install using Homebrew or download manually from releases. $ brew install

Trup-rewrite in rust! Finally!

Trup, but Rust! A Discord bot for the Unixporn community Now written in a good language! Dependencies Rust nightly sqlx-cli (if you need to change the

A collection of small Rust programs for doing weird things

This is a repo of small programs, proof of concepts, or templates written in Rust that relate in some way to hacking and/or CTF. I think Rust is real

Comments
  • Supporting `*_with()` construct, similar to Rayon's `map_with()`

    Supporting `*_with()` construct, similar to Rayon's `map_with()`

    Would it make sense to add parallel_map(init, func)? This is similar to how Rayon allows per-thread cloning, e.g. map_with. Ideally cloning should only be done once per thread, not once per mapping function callback. I could try to hack a PR if it is acceptable, but any starting pointers would be awesome. Also, there might be too many function name combinations - as it would essentially double the number of existing functions.

    opened by nyurik 4
  • use Vec to handle out-of-order items

    use Vec to handle out-of-order items

    The # of out-of-order items is IMO bounded by the # of threads. In any case it is relatively small and I don't see why a HashMap should perform any better than a simple Vec (especially given that the HashMap uses Vec-like buckets which are simple sequentially searched - I could imagine that we typically have a HashMap with just 1 bucket...)

    opened by aawsome 3
  • Iterator + 'static

    Iterator + 'static

    I love this crate, it's exactly what I need and I use it frequently. Thank you!

    It seems like you can't use the unscoped methods unless you're iterating over static values; is that right? That's fine, but I just want to make sure I'm not confused. The README doesn't mention that limitation, but does talk about e.g using .cloned() to help with the issue of borrowed references, which I've tried but there's still the issue of e.g. parallel_map requiring Iterator + 'static.

    opened by wiseman 1
  • Difference with ordered-parallel-iterator

    Difference with ordered-parallel-iterator

    Hi, thanks for creating pariter! I was researching this topic, and saw that there is another, more downloaded but less maintained crate called ordered-parallel-iterator. Do you know if its similar, or how does pariter differs from it? I see that it has a bit of a different API. I'm sure other devs may have the same question, would be great if the README included comparison with the other similar project. Thanks again!!!

    opened by nyurik 1
Owner
Dawid Ciężarkiewicz
Born 1985, programming since ~1993, on Linux ~1998, professionally ~2003, on github ~2008, with Rust ~2013. Deep&wide generalist, FOSS enthusiast.
Dawid Ciężarkiewicz
Parallel finance a decentralized lending protocol built on top of the Polkadot ecosystem. Our unique approach will allow users to earn "double interests" from staking and lending their tokens simultaneously.

Parallel Finance A new Cumulus-based Substrate node, ready for hacking ?? Getting Started Follow these steps to get started with the Cumulus Template

parallel-finance 100 Dec 17, 2022
A library to listen to global hotkeys in Rust

Rust Hotkey A library to listen to global hotkeys in Rust How to use See the examples folder for how to use this library. OS Support This lib aims to

James Birtles 44 Dec 12, 2022
minimalistic command launcher in rust

rrun Note: Apart from the occasional fix, this project is not actively developed anymore. rrun works fine and should run/compile for the time being on

null 105 Nov 18, 2022
Yet another fancy watcher. (Rust)

funzzy Yet another fancy watcher. (Inspired by antr / entr) Configure execution of different commands using semantic yaml. # .watch.yaml # list here a

Cristian Oliveira 188 Dec 12, 2022
A modern replacement for ps written in Rust

procs procs is a replacement for ps written in Rust. Documentation quick links Features Platform Installation Usage Configuration Features Output by t

null 3.6k Jan 5, 2023
A more intuitive version of du in rust

Dust du + rust = dust. Like du but more intuitive. Why Because I want an easy way to see where my disk is being used. Demo Install Cargo cargo install

andy.boot 5.5k Jan 8, 2023
Blazing 💥 fast terminal-ui for git written in rust 🦀

Blazing fast terminal client for git written in Rust Features Fast and intuitive keyboard only control Context based help (no need to memorize tons of

Stephan Dilly 11.8k Jan 5, 2023
A simple and fast download accelerator, written in Rust

zou A simple and fast download accelerator, written in Rust Zou is a Snatch fork by @k0pernicus. Snatch is a fast and interruptable download accelerat

Antonin Carette 173 Dec 4, 2022
Fuzzy Finder in rust!

Life is short, skim! Half of our life is spent on navigation: files, lines, commands… You need skim! It is a general fuzzy finder that saves you time.

Jinzhou Zhang 3.7k Jan 4, 2023
A bash-like Unix shell written in Rust

Cicada Unix Shell Cicada is a simple Unix shell written in Rust. Documents Install cicada Environment Variables Cicada Builtins Completion RC File His

Hugo Wang 921 Dec 28, 2022