rayon

Simple, guaranteed data-race-free work-stealing parallelism for Rust — turn sequential iterators parallel by changing one call.

Library
Cargo
v1.12.0
13,398 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
56 /100 Fair
Development Activity 40
Maintenance 20
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 92
Code Quality 90
Innovation 90
Learning Curve 85

Rayon is a lightweight data-parallelism library for Rust that makes it trivial to convert sequential computations into parallel ones. In most cases you simply swap a .iter() call for .par_iter() and Rayon handles dividing the work across a global work-stealing thread pool, dynamically adapting to the runtime workload for maximum throughput.

Built on top of rayon-core, Rayon’s APIs guarantee data-race freedom through Rust’s type system: if your code compiles, it typically produces the same results it did sequentially. Beyond parallel iterators, it exposes lower-level join and scope primitives and configurable thread pools for cases that need finer control.

What You Get

  • Parallel iterators (par_iter, par_iter_mut, into_par_iter) that mirror the standard iterator API
  • Low-level join and scope primitives for building custom parallel task trees
  • Configurable thread pools via ThreadPoolBuilder, including customization of the global pool
  • Parallel sorting (par_sort) and parallel collection extension (par_extend)
  • A prelude module that brings all the necessary traits into scope with one import

Common Use Cases

  • Parallelizing CPU-bound map/filter/reduce pipelines over large slices or vectors
  • Speeding up numeric and scientific computations across all available cores
  • Sorting large datasets in parallel with par_sort
  • Fanning out independent recursive work (e.g. divide-and-conquer algorithms) via join

Under The Hood

Architecture — Rayon is split into two crates: the user-facing rayon crate (parallel iterators over std types in src/iter, src/slice, src/str, src/collections, plus the prelude) and rayon-core, which houses the runtime — the work-stealing registry.rs, job.rs, latch.rs, the sleep module for idle-thread parking, and the join, scope, spawn, broadcast, and thread_pool primitives. Parallel iterators build a lazy computation graph of producers/consumers that is only executed when a terminal method is called, at which point work is split recursively and fed to the global work-stealing pool.

Tech Stack — Pure Rust (99.98% of the codebase), edition 2024, requiring rustc 1.85+. The runtime depends on crossbeam-deque and crossbeam-utils for lock-free work-stealing deques and synchronization; the public API re-exports either. Optional wasm_sync powers a spin-lock fallback on the browser main thread for wasm32 targets. The workspace also contains rayon-demo for benchmarks and visualizations.

Code Quality — Mature and disciplined. The workspace enforces strict lints (unsafe-op-in-unsafe-fn, unreachable-pub, private-bounds, and rust_2018_idioms all denied/warned). Testing is thorough: 16 integration test files under tests/ cover panic safety, unwind behavior, cross-pool usage, unzip edge cases, and large workloads (octillion.rs), alongside compile_fail tests that assert the type system rejects unsound usage. Roughly 2,300 commits over a decade of maintenance by 160 contributors.

API Design — Exceptionally ergonomic. The core design goal — swap iter() for par_iter() — makes adoption nearly friction-free, and the rayon::prelude::* import brings every needed trait into scope in one line. Naming deliberately mirrors the standard library’s iterator methods, so existing Rust knowledge transfers directly. Documentation is strong: extensive rustdoc with runnable examples, a README quick-start, and a FAQ. The join/scope escape hatches keep advanced control available without complicating the common path.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers