Performance targets

10M+
OPS / SEC
BIND operations at D=10K on commodity hardware
12 KB
PER VECTOR
Memory footprint at D=10,000
0
ALLOCATIONS
Zero-copy hot path — no heap allocations
<1ms
LATENCY
Full inference chain at D=10K

Why Rust

The core engine is written in Rust for three reasons:

Memory layout

Each ternary value (+1, 0, −1) is packed into 2 bits, giving 4 values per byte. A vector of dimension D = 10,000 occupies 2,500 bytes — small enough to fit in L1/L2 cache on most processors.

// Ternary packing: 4 values per byte
// 00 = absent (0)
// 01 = presence (+1)
// 10 = negation (−1)
// 11 = unused (reserved)

struct TernaryVec {
    data: Box<[u8]>,     // packed ternary values
    dim:  usize,           // logical dimension
}

Batch operations use Structure-of-Arrays (SoA) layout: N vectors stored as N/8 bytes for value-position-0, then N/8 bytes for value-position-1, and so on. This gives optimal cache behavior for batch BIND and SUPERPOSE.

SIMD optimization

BIND (element-wise multiplication) maps directly to SIMD instructions:

// Pseudocode for SIMD BIND
// Process 16 ternary values per cycle
fn bind_simd(a: &TernaryVec, b: &TernaryVec) -> TernaryVec {
    for chunk in a.data.chunks_exact(4).zip(b.data.chunks_exact(4)) {
        // 2-bit lookup table for ternary multiply
        // Result written directly — no intermediate allocation
    }
}

At D = 10,000, a single BIND requires ~2,500 byte operations — approximately 160 SIMD cycles on AVX2 (256-bit registers). This is why we achieve 10M+ operations per second.

Python bindings

PyO3 provides zero-overhead FFI between Python and the Rust core:

import mindprism as mp

// Create vectors
color = mp.random_vector(D=10000)
red   = mp.random_vector(D=10000)

// Bind and query
color_red = mp.bind(color, red)
result    = mp.bind(color_red, color)  // ≈ red

// Check similarity
print(mp.similarity(result, red))  // 0.94+

The Python API mirrors the algebra 1:1. No hidden abstractions — every function corresponds to a single algebraic operation.

Regression guarantees

Every build runs 10 million property tests validating:

Any PR that breaks a property test is rejected — the math must never drift.