Struct SimdPriceLevels

Source
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: usize

Number of valid levels currently stored (may be less than allocated capacity)

Implementations§

Source§

impl<const N: usize> SimdPriceLevels<N>

Source

pub fn new() -> Self

Create new SIMD price levels with const generic capacity

Source

pub fn with_capacity(capacity: usize) -> Self

Create new SIMD price levels with specified capacity (for compatibility)

Source

pub fn from_levels(levels: &[PriceLevel]) -> Self

Create from a slice of PriceLevel

Source

pub fn from_smallvec<const M: usize>(levels: &SmallVec<[PriceLevel; M]>) -> Self

Convert from SmallVec of PriceLevel

Source

pub fn total_volume(&self) -> f64

Get total volume using SIMD

Source

pub fn weighted_average_price(&self) -> Option<f64>

Calculate weighted average price using SIMD

Source

pub fn cumulative_volume_to_target( &self, target_volume: f64, ) -> Option<(usize, f64)>

Find the cumulative volume up to a target volume

Source

pub fn clear(&mut self)

Clear all price levels (compatibility method)

Trait Implementations§

Source§

impl<const N: usize> Clone for SimdPriceLevels<N>

Source§

fn clone(&self) -> SimdPriceLevels<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for SimdPriceLevels<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for SimdPriceLevels<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for SimdPriceLevels<N>

§

impl<const N: usize> RefUnwindSafe for SimdPriceLevels<N>

§

impl<const N: usize> Send for SimdPriceLevels<N>

§

impl<const N: usize> Sync for SimdPriceLevels<N>

§

impl<const N: usize> Unpin for SimdPriceLevels<N>

§

impl<const N: usize> UnwindSafe for SimdPriceLevels<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,