RECOMMENDATION: DO NOT integrate Rayon for LRU batch operations
Rayon parallelization shows severe performance regression across all dataset sizes:
The parallel overhead from thread spawning, synchronization, and work distribution far exceeds any benefits from parallelism for these workloads.
| Dataset Size | Sequential Time | Parallel Time | Speedup Ratio | Performance |
|---|---|---|---|---|
| 100 | 9.35 µs | 216.6 µs | 0.043x (23x slower) | ❌ Severe regression |
| 1000 | 114.6 µs | 1.158 ms | 0.099x (10x slower) | ❌ Severe regression |
| 10000 | 1.518 ms | 5.892 ms | 0.258x (3.9x slower) | ❌ Severe regression |
Throughput Comparison:
| Dataset Size | N (10%) | Sequential Time | Parallel Time | Speedup Ratio | Performance |
|---|---|---|---|---|---|
| 100 | 10 | 9.25 µs | 219.8 µs | 0.042x (24x slower) | ❌ Severe regression |
| 1000 | 100 | 95.8 µs | 1.164 ms | 0.082x (12x slower) | ❌ Severe regression |
| 10000 | 1000 | 1.145 ms | 6.200 ms | 0.185x (5.4x slower) | ❌ Severe regression |
Throughput Comparison:
| Size | Sequential | Parallel | Overhead | Regression |
|---|---|---|---|---|
| 10 | 1.19 µs | 85.9 µs | 84.7 µs | 72x slower |
| 50 | 6.26 µs | 99.7 µs | 93.4 µs | 16x slower |
| 100 | 12.41 µs | 204.4 µs | 192.0 µs | 16x slower |
| 500 | 58.68 µs | 662.4 µs | 603.7 µs | 11x slower |
| 1000 | 128.9 µs | 1.086 ms | 957.1 µs | 8.4x slower |
| 5000 | 768.8 µs | 3.347 ms | 2.578 ms | 4.4x slower |
| 10000 | 1.615 ms | 6.174 ms | 4.559 ms | 3.8x slower |
High thread spawning overhead: Each parallel operation spawns thread pool workers
Minimal per-item work: LRU operations are extremely fast
recency() lookup: ~0.09-0.16 µs per item (sequential)Synchronization costs: Parallel collection requires atomic operations
No CPU-bound work: LRU lookups are memory-bound, not compute-bound
There is NO break-even point in the tested range (10-10,000 items).
Extrapolating the trend:
Even at break-even, the gain would be minimal and not worth the complexity.
| Criterion | Target | Actual Result | Pass/Fail |
|---|---|---|---|
| Speedup @ 1K items | >2x | 0.1x (10x slower) | ❌ FAIL |
| Speedup @ 10K items | >3x | 0.25x (4x slower) | ❌ FAIL |
| Small dataset impact | <10% regression | 1600-7200% regression | ❌ FAIL |
| Thread efficiency | >70% | ~25% | ❌ FAIL |
Decision: REJECT Rayon integration
Since Rayon parallelization is not beneficial, consider these alternatives:
Instead of parallelism, optimize the sequential path:
Vec::with_capacity()If LRU data comes from external sources:
tokio for async I/O concurrencyLet users parallelize at a higher level:
The empirical benchmarking clearly demonstrates that Rayon parallelization provides no benefit for LRU batch operations and causes severe performance regressions across all tested dataset sizes.
Actions Taken:
Actions NOT Taken:
Cleanup Recommendations:
benches/rayon_evaluation_benchmarks.rs for documentation purposesrayon dependency from Cargo.toml (was added for evaluation only)The sequential implementation remains the optimal choice for this use case.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |