pub struct SimdPriceLevels<const N: usize = 64> {
pub prices: VecSimd<f64x4>,
pub quantities: VecSimd<f64x4>,
pub count: usize,
}Expand description
SIMD-aligned price levels for high-performance order book processing with const generic capacity
§Cache-Aligned Memory Architecture for Order Book Data
This structure uses cache-aligned SIMD buffers to optimize order book analytics:
- Separate Price/Quantity Buffers: Prevents cache line conflicts during calculations
- 32-byte Alignment: Each f64x4 vector aligns to cache line boundaries
- Vectorized Operations: Process 4 price levels simultaneously using SIMD
- Memory Bandwidth Optimization: Sequential access patterns maximize throughput
§Performance Benefits for Order Book Analytics
Cache alignment provides significant performance improvements:
- 3-5x faster order book imbalance calculations
- Reduced memory latency from aligned SIMD loads (2-4x improvement)
- Optimal cache utilization prevents false sharing between price/quantity data
- Vectorized depth calculations for weighted price levels
§Memory Layout Diagram
Cache-Aligned Order Book Levels:
prices: [price0][price1][price2][price3] <- 32-byte aligned f64x4
quantities: [qty0 ][qty1 ][qty2 ][qty3 ] <- 32-byte aligned f64x4§HFT Order Book Use Cases
Optimized for real-time market microstructure analytics:
- Order Flow Imbalance (OFI) calculations
- Volume-Weighted Average Price (VWAP) for price levels
- Order book depth and spread analysis
- Multi-level liquidity measurements
Fields§
§prices: VecSimd<f64x4>Cache-aligned SIMD buffer for price levels Uses f64x4 vectors for processing 4 price levels simultaneously
quantities: VecSimd<f64x4>Cache-aligned SIMD buffer for quantity levels Separate buffer prevents false sharing during price/quantity calculations
count: usizeNumber of valid levels currently stored (may be less than allocated capacity)
Implementations§
Source§impl<const N: usize> SimdPriceLevels<N>
impl<const N: usize> SimdPriceLevels<N>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create new SIMD price levels with specified capacity (for compatibility)
Sourcepub fn from_levels(levels: &[PriceLevel]) -> Self
pub fn from_levels(levels: &[PriceLevel]) -> Self
Create from a slice of PriceLevel
Sourcepub fn from_smallvec<const M: usize>(levels: &SmallVec<[PriceLevel; M]>) -> Self
pub fn from_smallvec<const M: usize>(levels: &SmallVec<[PriceLevel; M]>) -> Self
Convert from SmallVec of PriceLevel
Sourcepub fn total_volume(&self) -> f64
pub fn total_volume(&self) -> f64
Get total volume using SIMD
Sourcepub fn weighted_average_price(&self) -> Option<f64>
pub fn weighted_average_price(&self) -> Option<f64>
Calculate weighted average price using SIMD
Trait Implementations§
Source§impl<const N: usize> Clone for SimdPriceLevels<N>
impl<const N: usize> Clone for SimdPriceLevels<N>
Source§fn clone(&self) -> SimdPriceLevels<N>
fn clone(&self) -> SimdPriceLevels<N>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read more