A lightweight data-parallelism library for Rust that makes it easy to convert sequential computations into parallel ones.
Rayon is a data-parallelism library for Rust that simplifies parallel programming by enabling developers to easily convert sequential iterators into parallel ones. It guarantees data-race freedom, ensuring that parallel execution is safe and behaves the same as sequential code if it compiles. The library is lightweight and dynamically adapts for performance, with support for custom thread pools and WebAssembly.
Rust developers working on CPU-intensive tasks or data processing who want to add parallelism with minimal code changes and guaranteed safety. It is particularly suited for those building applications like simulations, data transformations, or computational workloads that can benefit from multi-core execution.
Developers choose Rayon because it offers a simple, drop-dead easy API—often just changing `iter()` to `par_iter()`—while leveraging Rust's type system to eliminate data races at compile time. Its dynamic performance adaptation and flexibility with custom task creation provide efficiency and control without sacrificing safety.
Rayon: A data parallelism library for Rust
Simply changing `iter()` to `par_iter()` enables parallel execution, as shown in the sum_of_squares example, with minimal code changes and no manual thread management.
APIs ensure that if code compiles, it behaves identically to sequential code, leveraging Rust's type system to eliminate most parallel bugs at compile time.
Parallel iterators adaptively divide tasks at runtime to maximize CPU utilization, providing efficient execution without requiring manual tuning or configuration.
Beyond iterators, functions like `join` and `scope` allow custom parallel task creation, and custom thread pools offer control over resource allocation beyond the global default.
By default, Rayon runs sequentially on WebAssembly for compatibility, with optional multithreading via adapters like wasm-bindgen-rayon, ensuring broad platform support.
Parallel execution can reorder side effects like I/O or channel sends, which may break assumptions in code relying on sequential ordering, as noted in the README caveat.
Enabling true parallelism on WebAssembly requires additional dependencies and configuration, such as wasm-bindgen-rayon, adding setup overhead compared to native thread support.
For small data sets or simple operations, the cost of task spawning and synchronization might outweigh parallelism benefits, making sequential code faster in lightweight scenarios.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.