Expand description
§ZeroPool - High-Performance Buffer Pool for Rust
ZeroPool provides a thread-safe buffer pool optimized for high-throughput I/O workloads.
It achieves exceptional performance through:
- System-aware defaults: Automatically adapts to CPU count and hardware topology
- Thread-local caching: Lock-free fast path with adaptive cache size (2-8 buffers)
- Sharded global pool: Reduces contention with CPU-scaled sharding (4-128 shards)
- Zero-copy operations: Avoids unnecessary memory allocations and copies
- Smart buffer reuse: First-fit allocation with configurable size limits
§Performance
In benchmarks with 500MB buffers, ZeroPool achieves:
- 70% faster than no pooling (176ms → 52ms)
- 3.36x speedup through buffer reuse
- Lock-free fast path for single-threaded workloads
- Scales automatically from embedded systems to 128+ core servers
§Quick Start
use zeropool::BufferPool;
// Create a pool with smart defaults
let pool = BufferPool::new();
// Get a buffer
let mut buffer = pool.get(1024 * 1024); // 1MB buffer
// Use the buffer for I/O operations
// ... read/write operations ...
// Return buffer to pool for reuse
pool.put(buffer);§Custom Configuration
Use the builder pattern for custom configuration:
use zeropool::BufferPool;
let pool = BufferPool::builder()
.min_buffer_size(512 * 1024) // Keep buffers >= 512KB
.tls_cache_size(8) // 8 buffers per thread
.max_buffers_per_shard(32) // Up to 32 buffers per shard
.num_shards(16) // Override CPU-based default
.build();§System-Aware Scaling
ZeroPool automatically adapts to your system:
| System | Cores | TLS Cache | Shards | Buffers/Shard | Total Capacity |
|---|---|---|---|---|---|
| Embedded | 4 | 4 | 4 | 16 | 64 (~64MB) |
| Laptop | 8 | 6 | 8 | 16 | 128 (~128MB) |
| Workstation | 16 | 6 | 8 | 32 | 256 (~256MB) |
| Small Server | 32 | 8 | 16 | 64 | 1024 (~1GB) |
| Large Server | 64 | 8 | 32 | 64 | 2048 (~2GB) |
| Supercompute | 128 | 8 | 64 | 64 | 4096 (~4GB) |
§Safety
ZeroPool uses targeted unsafe optimizations for maximum performance while maintaining memory safety guarantees:
-
set_len()instead ofresize(): When reusing pooled buffers, we use unsafeset_len()to avoid redundant zero-initialization. This is safe because:- Capacity is always verified before setting length
- Buffers are pooled (previously allocated and cleared)
- Users receive initialized memory (may contain previous data, but no UB)
-
Unchecked shard indexing: Shard index is masked with
shard_mask(power of 2 - 1), guaranteeing bounds. Usingget_uncheckedeliminates redundant bounds checks. -
Optional memory pinning: When
pinned_memoryis enabled, buffers are locked in RAM usingmlockto prevent swapping. This is best-effort and fails gracefully if insufficient permissions. Useful for security-sensitive or latency-critical workloads.
Structs§
- Buffer
Pool - A high-performance, thread-safe buffer pool optimized for I/O workloads
- Builder
- Builder for configuring a
BufferPool