VelocityX
A comprehensive lock-free data structures library designed for high-performance concurrent programming in Rust.
๐ Features
- MPMC Queue - Multi-producer, multi-consumer bounded queue with zero locks
- Concurrent HashMap - Lock-free reads with concurrent modifications using striped locking
- Work-Stealing Deque - Chase-Lev deque for task scheduling and parallel workload distribution
- Zero-Cost Abstractions - Optimized for modern multi-core processors
- Memory Safety - Comprehensive safety guarantees through Rust's type system
- Ergonomic APIs - Designed to guide users toward correct concurrent programming patterns
Performance
| Data Structure | VelocityX | std::sync | crossbeam | Improvement |
|---|---|---|---|---|
| Bounded MPMC Queue | 45M ops/s | 15M ops/s | 28M ops/s | 3.0x |
| Unbounded MPMC Queue | 38M ops/s | 12M ops/s | 25M ops/s | 3.2x |
| Concurrent HashMap | 52M ops/s | 18M ops/s | 35M ops/s | 2.9x |
| Work-Stealing Deque | 41M ops/s | N/A | 22M ops/s | 1.9x |
Data Structures
MPMC Queue
Multi-producer, multi-consumer queues in both bounded and unbounded variants:
use MpmcQueue;
// Bounded queue for predictable memory usage
let queue: = new;
queue.push?;
let value = queue.pop;
assert_eq!;
// Consumer thread
let consumer = spawn;
producer.join.unwrap;
let result = consumer.join.unwrap;
assert_eq!;
Concurrent HashMap
use ConcurrentHashMap;
use thread;
let map = new;
// Writer thread
let writer = spawn;
// Reader thread
let reader = spawn;
writer.join.unwrap;
let result = reader.join.unwrap;
assert_eq!; // Sum of 0, 2, 4, ..., 1998
Work-Stealing Deque
use WorkStealingDeque;
use thread;
let deque = new;
// Owner thread (worker)
let owner = spawn;
// Thief thread (stealer)
let thief = spawn;
owner.join.unwrap;
let stolen_count = thief.join.unwrap;
println!;
๐ Documentation
API Documentation
Comprehensive API documentation is available on docs.rs.
Performance Characteristics
| Data Structure | Push | Pop | Get | Insert | Remove | Memory Ordering |
|---|---|---|---|---|---|---|
| MPMC Queue | O(1) | O(1) | - | - | - | Release/Acquire |
| Concurrent HashMap | - | - | O(1) | O(1) | O(1) | Acquire/Release |
| Work-Stealing Deque | O(1) | O(1) | - | - | - | Release/Acquire |
Thread Safety Guarantees
- MPMC Queue: Completely lock-free, safe for concurrent access from any number of threads
- Concurrent HashMap: Lock-free reads, striped locking for writes
- Work-Stealing Deque: Owner operations are lock-free, thief operations are lock-free
๐๏ธ Architecture
Design Principles
- Cache-Line Alignment: Critical data structures are aligned to cache line boundaries to prevent false sharing
- Memory Ordering: Careful use of memory ordering semantics for correctness and performance
- ABA Prevention: Proper handling of ABA problems in lock-free algorithms
- Incremental Operations: Non-blocking resize and rehash operations where possible
Memory Layout
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ VelocityX โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Queue Module โ
โ โโโ MpmcQueue (lock-free ring buffer) โ
โ โโโ Cache-aligned atomic indices โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Map Module โ
โ โโโ ConcurrentHashMap (striped locking) โ
โ โโโ Robin hood hashing โ
โ โโโ Incremental resizing โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Deque Module โ
โ โโโ WorkStealingDeque (Chase-Lev) โ
โ โโโ Owner/thief operations โ
โ โโโ Circular buffer โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐งช Testing
VelocityX includes comprehensive testing:
- Unit Tests: Individual operation correctness and edge cases
- Concurrency Tests: High-contention scenarios with multiple threads
- Stress Tests: Long-running stability tests
- Property-Based Tests: Randomized testing with invariants
- Memory Safety Tests: Drop safety and memory leak detection
Run tests with:
For comprehensive testing including stress tests:
๐ Benchmarks
Performance benchmarks comparing VelocityX against standard library alternatives:
Benchmark Results (Intel i7-9700K, Rust 1.65)
| Operation | VelocityX | Std Library | Improvement |
|---|---|---|---|
| MPMC Queue Push | 45 ns/op | 120 ns/op | 2.7x faster |
| MPMC Queue Pop | 38 ns/op | 95 ns/op | 2.5x faster |
| HashMap Get | 25 ns/op | 65 ns/op | 2.6x faster |
| HashMap Insert | 85 ns/op | 180 ns/op | 2.1x faster |
| Deque Push | 32 ns/op | 78 ns/op | 2.4x faster |
| Deque Pop | 28 ns/op | 72 ns/op | 2.6x faster |
Results are approximate and may vary by hardware and workload.
๐ง Configuration
Feature Flags
default: Standard library supportserde: Serialization support for data structuresunstable: Unstable features (requires nightly Rust)test-stress: Additional stress tests (for testing only)
Optimization Tips
- Choose Right Capacity: Pre-size data structures to avoid resizing overhead
- Monitor Contention: Use size() methods to detect backpressure
- Batch Operations: When possible, batch operations to reduce atomic overhead
- NUMA Awareness: Consider NUMA topology for large deployments
๐ Use Cases
VelocityX is ideal for:
- High-Throughput Message Passing: Distributed systems, event sourcing
- Concurrent Task Scheduling: Async runtimes, thread pools
- Lock-Free Caching: Web applications, microservices
- Parallel Data Processing: ETL pipelines, analytics
- Real-Time Systems: Trading platforms, gaming servers
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
Code Quality
All code must pass:
๐ Support & Community
- ๐ Full Documentation: quefep.uk/velocityx
- ๐ API Reference: docs.rs/velocityx
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
๐ License
This project is dual-licensed under either:
at your option.
๐ Acknowledgments
VelocityX builds upon the foundational work of researchers and practitioners in concurrent programming:
- Maged Michael - Lock-free algorithms and memory reclamation
- Maurice Herlihy & Nir Shavit - Concurrent data structures theory
- Chase & Lev - Work-stealing deque algorithm
- Crossbeam Team - Excellent Rust concurrent primitives
VelocityX - High-performance concurrent data structures for Rust
๐ quefep.uk/velocityx | ๐ฆ crates.io/velocityx | ๐ docs.rs/velocityx