FrankenNumPy

Docs/Context

Performance Levers Applied So Far

Concrete optimization passes that have landed, paired with what they bought. Each lever follows the optimization-governance pattern in docs/planning/PROPOSED_ARCHITECTURE.md: baseline → profile → single lever → conformance check → re-baseline → proof artifact.

Lever What it does Where Effect
Contiguous-axis reduction kernel Replaces per-element unravel/ravel with a stride-aware fast path reduce_sum_axis_contiguous in fnp-ufunc/src/lib.rs Axis reductions on contiguous data ~56% p50 faster; commit d9cfe90 (2026-02-13). Proof bundle under artifacts/optimization/
Neumaier-compensated sum for large arrays Switches from naive accumulation to compensated sum above 1,000,000 finite elements reduce_sum_values, neumaier_sum_values Error stays at O(ε) per element instead of O(n·ε); no measurable runtime cost below threshold
Incremental odometer for broadcast index mapping Output-to-source mapping increments stride state in a loop instead of recomputing per element Inside elementwise_binary and the broadcast view machinery Cuts per-element overhead on broadcast ops; particularly noticeable at small-medium array sizes
2×2 linear-algebra fast paths Specialized closed-form solve_2x2, det_2x2, inv_2x2, qr_2x2, svd_2x2, eigh_2x2, cholesky_2x2 fnp-linalg/src/lib.rs Avoids LU/Householder/QR overhead for the most common small-matrix case; dominant cost is the 2-line algebraic formula
Horner / Clenshaw polynomial evaluation Standard nested multiplication for power-series; orthogonal-polynomial recurrence for Chebyshev/Legendre/Hermite/Laguerre Throughout fnp-ufunc polynomial section Numerical stability + minimal multiplications
Ziggurat sampling for normal / exponential First-acceptance rate ~97%; rejected samples fall through to tail or wedge handling fnp-random/src/ziggurat.rs Matches NumPy's per-sample cost characteristic
Zero-copy view machinery via Arc<RwLock<Vec<f64>>> Transpose, broadcast, sliding-window all produce views, not copies UFuncArrayView in fnp-ufunc/src/lib.rs Eliminates allocation on shape-only operations
Arc<[u8]> for NPY payloads NPY load returns Arc<[u8]> rather than Vec<u8>; downstream consumers share the payload without cloning NpyArrayBytes in fnp-io Zero-copy sharing of loaded payloads (commit 3ed4487)
8-element chunk processing for boolean mask count count_true_mask processes booleans in 8-element groups for vectorizable counting fnp-iter/src/lib.rs Helps the optimizer emit popcnt-style code
Bluestein chirp-Z FFT for non-power-of-2 Rewrites arbitrary-length DFT as power-of-2 convolution; uses Cooley–Tukey for the convolution fft_dit in fnp-ufunc/src/lib.rs Lets every FFT length go through a single fast path
Constant-time dtype promotion All 324 dtype pairs in a const fn match expression with no runtime allocation pub const fn promote(...) in fnp-dtype/src/lib.rs Promotion lookup is a couple of branches, not a hashmap

Future work in the Roadmap covers broader SIMD use, an optional BLAS backend, and further per-operation parallel refinements; targeted SIMD and Rayon paths have already landed. Every closed bead with a perf lever has a proof artifact in artifacts/optimization/; the same baseline/profile/lever/conformance/re-baseline cycle continues to apply.


This section in the README on GitHub