fast-yaml-parallel
Multi-threaded YAML processing with work-stealing parallelism.
Features
This crate provides two types of parallelism:
| Type | API | Use Case |
|---|---|---|
| Document-level | parse_parallel() |
Parse multi-document YAML streams (single file with --- separators) |
| File-level | FileProcessor |
Process multiple YAML files in parallel |
Installation
[]
= "0.5"
Or with cargo-add:
[!IMPORTANT] Requires Rust 1.88 or later.
Usage
Document-Level Parallelism
Parse a single file containing multiple --- separated documents:
use parse_parallel;
let yaml = "---\nfoo: 1\n---\nbar: 2\n---\nbaz: 3";
let docs = parse_parallel?;
assert_eq!;
# Ok::
With custom configuration:
use ;
let config = new
.with_workers // 8 threads
.with_sequential_threshold; // Skip parallelism for small inputs
let yaml = "---\nfoo: 1\n---\nbar: 2";
let docs = parse_parallel_with_config?;
# Ok::
File-Level Parallelism
Process multiple YAML files in parallel:
use PathBuf;
use ;
let files = vec!;
// Parse all files
let result: BatchResult = new.parse_files;
println!;
// With custom configuration
let config = new.with_workers;
let processor = with_config;
let result = processor.parse_files;
# Ok::
Format files in place:
use PathBuf;
use FileProcessor;
use EmitterConfig;
let files = vec!;
let emitter_config = new.with_indent.with_width;
let processor = new;
let result = processor.format_in_place;
println!;
# Ok::
Convenience Function
Quick file processing without creating a processor:
use PathBuf;
use process_files;
let files = vec!;
let result = process_files;
assert!;
Configuration
| Option | Default | Description |
|---|---|---|
workers |
Auto (CPU cores) | Number of worker threads. None = auto, Some(0) = sequential |
mmap_threshold |
512 KB | Use memory-mapped I/O for files larger than this |
max_input_size |
100 MB | Maximum input size (DoS protection) |
sequential_threshold |
4 KB | Skip parallelism for inputs smaller than this |
Configuration Example
use Config;
let config = new
.with_workers // 8 threads
.with_mmap_threshold // 1 MB mmap threshold
.with_max_input_size // 50 MB max
.with_sequential_threshold; // 8 KB sequential threshold
Result Types
BatchResult
Aggregated result from file processing:
FileOutcome
Outcome for individual file:
Performance
Expected speedup on multi-core systems:
| Cores | Document-Level | File-Level |
|---|---|---|
| 4 | 3-3.5x | 3-4x |
| 8 | 6-6.5x | 6-8x |
| 16 | 10-12x | 12-15x |
[!TIP] Run benchmarks with
cargo bench -p fast-yaml-parallelto measure on your hardware.
Related Crates
This crate is part of the fast-yaml workspace:
fast-yaml-core— Core YAML 1.2.2 parser and emitterfast-yaml-linter— YAML linting with rich diagnostics
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.