rustfs-erasure-codec
English | 中文
rustfs-erasure-codec is a modern Rust implementation of Reed-Solomon erasure coding for
memory-resident, progressive, and block-streaming workloads.
The current 7.0.0 line provides:
- classic Reed-Solomon over
GF(2^8)andGF(2^16) - runtime-dispatched SIMD backends for
galois_8 - Leopard GF8 and Leopard GF16 codec families
- incremental and targeted recovery APIs
- reusable verification and reconstruction buffers
- block-based streaming encode, verify, and reconstruct APIs
no_stdsupport and a WASM companion crate
WASM bindings live in wasm/README.md.
Highlights
galois_8::ReedSolomonis the main optimized path for general-purpose use.galois_16::ReedSolomonremains available for classicGF(2^16)workflows.CodecOptionscontrols codec family, matrix mode, inversion-cache behavior, and parallel policy.VerifyWorkspace,ShardSlot<T>, and aligned-shard helpers reduce hot-path allocation churn.galois_8::OptionVecReconstructWorkspacereuses planning for repeatedOption<Vec<u8>>reconstruct calls with a stable missing pattern.decode_idx(...),reconstruct_some(...), andShardByShardcover progressive and selective workflows.stream::StreamOptionsprovides block-based streaming on the classicgalois_8path.
Install
Add the crate:
[]
= "7.0.0"
Enable SIMD acceleration when throughput matters:
[]
= { = "7.0.0", = ["simd-accel"] }
Or enable a narrower backend set:
[]
= { = "7.0.0", = ["simd-neon"] } # aarch64
# rustfs-erasure-codec = { version = "7.0.0", features = ["simd-ssse3"] } # x86_64
# rustfs-erasure-codec = { version = "7.0.0", features = ["simd-avx2"] } # x86_64
# rustfs-erasure-codec = { version = "7.0.0", features = ["simd-avx512"] }# x86_64
# rustfs-erasure-codec = { version = "7.0.0", features = ["simd-gfni"] } # x86_64
# rustfs-erasure-codec = { version = "7.0.0", features = ["simd-vsx"] } # powerpc64
Notes:
stdis enabled by default.simd-accelis the umbrella feature that enables all supported SIMD backends.- Runtime dispatch is safe: unsupported ISAs fall back to scalar execution.
Quick Start
use ReedSolomon;
use VerifyWorkspace;
For repeated verification calls, prefer verify_with_workspace(...) or
verify_with_buffer(...) over plain verify(...).
For repeated Option<Vec<u8>> reconstruct calls that keep the same missing
pattern, prepare a reusable reconstruct workspace once and reuse it across
calls:
use ReedSolomon;
let rs = new.unwrap;
let mut shards = vec!;
rs.encode.unwrap;
let mut missing: = shards.into_iter.map.collect;
missing = None;
missing = None;
let workspace = rs.prepare_reconstruct_opt_workspace.unwrap;
rs.reconstruct_opt_with_workspace.unwrap;
Memory Reuse Helpers
For repeated reconstruct flows, ShardSlot<T> lets you keep ownership of missing-shard buffers:
use ;
For SIMD-sensitive galois_8 workloads, aligned shard helpers are available:
rustfs_erasure_codec::galois_8::alloc_aligned_shards(...)galois_8::ReedSolomon::alloc_aligned(...)
Codec Families
CodecOptions::codec_family selects the algorithm family:
| Family | Status | Notes |
|---|---|---|
Classic |
fully supported | Default family. Supports update, encode_single*, decode_idx, reconstruct_some, and matrix-mode selection. |
LeopardGF8 |
supported on the galois_8 path |
FFT-based codec over GF(2^8). Requires shard lengths that are multiples of 64 bytes and supports up to 256 total shards. Classic-only APIs such as update, encode_single*, and decode_idx are not supported. |
LeopardGF16 |
supported for high shard-count workflows | FFT-based codec over GF(2^16) for larger total shard counts. Classic-only APIs such as update, encode_single*, and decode_idx are not supported. |
Example:
use ReedSolomon;
use ;
let rs = with_options
.unwrap;
Important Leopard-family notes:
- shard lengths must be multiples of 64 bytes
- all shard buffers must be the same length
decode_idx(...),update(...), andencode_single*remain Classic-only
Matrix Modes
CodecOptions::matrix_mode applies to CodecFamily::Classic:
VandermondeCauchyJerasureLikeCustom
If you need compatibility with established classic payload layouts, stay on
MatrixMode::Vandermonde.
Minimal custom-matrix example:
use ReedSolomon;
use CodecOptions;
let custom_rows = vec!;
let rs = with_custom_matrix.unwrap;
Progressive And Targeted APIs
Progressive Recovery
decode_idx(...) is available on classic galois_8::ReedSolomon and is useful when input shards arrive in phases instead of a single reconstruct call.
Targeted Recovery
reconstruct_some(...) reconstructs only the shards you mark as required.
Shard-By-Shard Encoding
ShardByShard provides a stateful progressive encoder for workflows that feed data shards incrementally.
Streaming API
The streaming API lives under rustfs_erasure_codec::stream and is available with the default std feature.
Main entry points:
encode_stream(...)verify_stream(...)reconstruct_stream(...)
Current scope and limitations:
- implemented on the classic
galois_8path - tuned for block-based processing via
StreamOptions reconstruct_stream(...)currently usesCursor<Vec<u8>>- Leopard-family streaming reconstruction is not supported
Use this path when your data should be processed in bounded blocks instead of holding the full shard matrix in memory.
Runtime Backend Control
The galois_8 path exposes runtime backend inspection and override hooks.
Environment variables:
RSE_BACKEND_OVERRIDERSE_STRICT_BACKEND_OVERRIDE=1RUST_REED_SOLOMON_ERASURE_ARCH
Public helpers:
galois_8::active_backend_name()galois_8::active_backend_kind()galois_8::active_backend_id()
Tuning And Profiling
Useful CodecOptions knobs:
fast_one_parityinversion_cacheinversion_cache_capacitymax_parallel_jobs
Parallel-policy environment variables:
RS_PARALLEL_POLICY_MIN_PARALLEL_SHARD_BYTESRS_PARALLEL_POLICY_MIN_BYTES_PER_JOBRS_PARALLEL_POLICY_MAX_JOBSRS_PARALLEL_POLICY_L2_CACHE_BYTESRS_PARALLEL_POLICY_DEBUG
Optional metrics/profile surfaces:
benchmark-metricsfeatureleopard_gf8_profile_stats()reset_leopard_gf8_profile_stats()
Validation And Benchmarks
Common workflows:
# Run tests
# Run benchmarks
# Run release validation
# Run extended validation
VALIDATION_PROFILE=extended
# Collect x86_64 SIMD benchmark artifacts
Useful references:
Provenance
Versions 0.9.0 through 6.0.0 were originally created by
Darren Ldl and later maintained by the
rust-rse community.
The current 7.0.0 line in this repository is maintained under
houseme/reed-solomon-erasure
and reflects the Rust 2024 rewrite, runtime SIMD architecture, and Leopard work.
Contributing
Contributions are welcome. For backend-sensitive, benchmark-sensitive, or codec-family work, include focused validation where possible.
License
This project is released under the MIT License. See LICENSE.
The bundled simd_c sources derive from
Nicolas Trangez's Haskell implementation
and remain under the MIT License as well.