FrankenNumPy

Docs/Evidence

Performance

On this page 2 sections

FrankenNumPy is profile-driven: every optimization is paired with a baseline, a single targeted lever, and a proof-backed delta artifact.

Measured against NumPy (re-measured 2026-10-08)

Every ratio in the table below and in the loss-map paragraph comes from one run: fnp_python and NumPy's own function on the same operands in ONE process, interleaved with a NumPy-vs-NumPy A/A null, order reversed every other round (15 rounds), outputs checked equal to NumPy's before timing, and the incumbent arm asserted at runtime to be NumPy's own object. Host thinkstation1 (AMD Ryzen Threadripper PRO 5975WX, 64 logical CPUs, load ~4-6 during the runs), NumPy 2.4.3, fnp_python built with --profile release-perf at 15ab8e3e5, default thread pools. Speedup = NumPy time / fnp time (median). The data, with hashes of both arms, is artifacts/perf-scorecard-2026-10-08.json; each row resolves to a 2026-10-08 row of docs/NEGATIVE_EVIDENCE.md.

Capability Speedup vs NumPy (shape) No native win at this shape
float16 (NumPy has no f16 arithmetic or BLAS) matmul 256x256 59x; nan_to_num 17x, floor 15x, clip 14x, isnan 12x, exp 9.6x (2^20); nanstd axis=1 18x, var axis=0 14x (1024x1024) var with no axis (NumPy's own route)
Integer GEMM (no integer BLAS in NumPy) matmul int64 256x256 20x, tensordot 17x, batched matmul (64,64,64) 14x
Sort / set operations isin f64 16M x 65,536 201x; sort bool 28x, int16 28x (2^20); unique int64 (65536,4) axis=0 11x argsort of 2^20 distinct int64
Reductions / scans gradient 2.2x, median int64 2.2x (2^20); nanmean axis=0 (4096,256) 1.9x argmax f64 2^20
Complex / temporal exp complex128 11.5x; argsort datetime64[ns] 4.9x (2^20)
Strings (65,536 x U16) strings.translate 69x, char.upper 16x, strings.replace 1.55x
Construction cross (3, 2^18) axis=0 3.1x tile, concatenate, pad (1M-element outputs)

Whole-surface loss map. scripts/perf_gap_sweep_vs_numpy.py --surface --json times every numpy.__all__ callable fnp_python implements itself (292 functions) on auto-probed float64 / int64 operands at 4,096 and 2^20 elements, fnp and NumPy interleaved with an A/A null per cell. Same build and host, default pools: of 929 cells, 38% run below 0.9x NumPy's time, 54% within 0.9-1.1x, 7% at 1.1-1.4x (mostly ~0.1-0.2 us of call overhead at 4,096 elements) and 5 above 1.4x. Re-timed alone, three fresh processes each, those 2^20 cells are much closer: ceil / floor f8 1.04-1.05x (2.3x in the sweep process), diff f8 1.00x and i8 1.02x (1.6x), right_shift i8 1.08-1.10x (1.5x); the sweep's large-n readings move with its process's memory layout, so a sweep cell is a lead to re-time, not a verdict. The f8 rounding maps run serially between their native threshold (2^17) and the 16 MiB parallel floor and trail NumPy's loop by ~4% there; at 2^22 they run 0.48-0.58x NumPy's time. With RAYON_NUM_THREADS=1: 30% below 0.9x, 8 cells above 1.4x (the f8 rounding family at 2^20, diff, right_shift, take i8). Data: artifacts/loss-map-2026-10-08-pool.json, artifacts/loss-map-2026-10-08-serial.json.

Whole jobs. The three end-to-end jobs of docs/PERF_RELEASE_READINESS_SCORECARD.md, re-run 2026-10-08 under their own contract (release-perf bench binary, 4 threads, NumPy/NumPy and FNP/FNP nulls per size, effect CI clearing twice the null half-width): int64 rolling-load saturation (convolve -> maximum.accumulate -> ptp over 2.2M-8.8M counts) 2.70-2.98x, float16 dynamic-range audit (frexp -> bincount -> ldexp over 2M-8M samples) 3.87-4.50x, int64 critical-access exposure (matmul -> max / argmax -> ptp over 4,096-16,384 accounts) 3.76-4.21x faster than NumPy, every size decidable and every output byte-identical.

What "byte-identical" covers. Every timed cell above returned NumPy's exact output. Routes that do not reproduce NumPy bit for bit — no-FMA cov / corrcoef on the shapes where they are native, einsum(optimize=False) on float64, stacked (3-D and up) linalg kernels — are listed in docs/DIVERGENCES.md with their stated bounds. The v0.2.0 campaign's headline table (June–July 2026) and its 2026-09-02 evidence-grade audit are kept in the ledger's 2026-10-08 scorecard row; losses, rejected levers and reverts stay in the append-only ledger.

The 2026-05-25 cross-engine baseline below predates both; it is retained as the parity-era snapshot of the delegated engine.

  • Release profile. The workspace Cargo.toml does not override [profile.release], so Cargo's defaults apply (opt-level = 3, lto = false, codegen-units = 16, strip = false). The workspace adds one custom profile, release-perf, defined explicitly: inherits = "release", lto = "thin", codegen-units = 1, debug = "line-tables-only". That is the right profile for flamegraph profiling. Downstream consumers that want full LTO are free to add [profile.release] lto = true in their own top-level Cargo.toml.
  • Contiguous reduction kernel. Axis reductions on contiguous data avoid per-element index computation. A targeted optimization pass (commit d9cfe90, 2026-02-13) reduced axis-reduction latency by ~56% (p50/p95/p99 deltas of ~90% on contiguous workloads). See artifacts/optimization/ and artifacts/baselines/ for the proof bundle.
  • Broadcast index mapping. Output-to-source index mapping uses an incremental odometer instead of full unravel/remap per element.
  • 2×2 fast paths. Linear algebra has specialized 2×2 implementations that bypass general NxN overhead for the most common small-matrix case.
  • Horner's method. Polynomial evaluation uses Horner form for numerical stability and minimal multiplications. The Stirling-series helpers in fnp-random (logfactorial for k > 125 and the binomial BTPE acceptance path) use the same evaluation style.
  • Ziggurat sampling. Normal and exponential random variates use Ziggurat (same as NumPy), which accepts ~97% of samples on the first try.

The G7 budget gate (scripts/e2e/run_performance_budget_gate.sh, deciding with run_performance_budget_gate --ab-*) builds generate_benchmark_baseline in release at the reference commit and at the candidate on the same runner, runs the ten sentinel workloads for 9 rounds in alternating order, and fails a workload only on a decidable median regression above 7%: the per-round candidate/reference ratio's bootstrap CI must exclude 1 and the effect must exceed twice the larger of the two arms' own round-to-round (A/A) spread. It also keeps absolute p95 ceilings and fails closed on missing SLO instrumentation. The cross-engine benchmark (run_cross_engine_benchmark) compares directly against NumPy. A complementary per-crate Criterion layer also exists — 66 bench files across 9 crates as of 2026-09-03 (every crate except fnp-runtime; the largest lane is fnp-python/benches/ with 25 criterion_python_<area>.rs targets plus the shared common/mod.rs dual-null median-CI harness that also prints bench_elf_sha256; other crates carry one to seven targets each — fnp-conformance/benches/criterion_core_ops.rs, fnp-dtype/benches/dtype_ops.rs, fnp-io/benches/criterion_io.rs, fnp-iter/benches/criterion_iter.rs, fnp-linalg/benches/ (7, incl. criterion_linalg, gemm_microkernel, tsqr), fnp-ndarray/benches/criterion_ndarray.rs, fnp-random/benches/ (2), fnp-ufunc/benches/ (21, incl. elementwise, transcendental, take_axis)) runnable via cargo bench -p <crate> for tracking within-FrankenNumPy regressions without going through NumPy. When adding a new bench, prefer the criterion_<area> form to match the more recent files. HTML reports (Criterion's html_reports feature, lifted to [workspace.dependencies]) are emitted under target/criterion/<bench>/report/index.html for every benched operation.

2026-05-25 cross-engine snapshot (13 workloads at 1M-element scale, 10 runs each, p50 ratios):

Op family Ratio (FNP / NumPy) Verdict
Multiply (1M) 0.89× FrankenNumPy wins
Add (1M) 0.91× FrankenNumPy wins
Mean (1M) 0.91× FrankenNumPy wins
Sort (100K) 0.91× FrankenNumPy wins
Std (1M) 0.92× FrankenNumPy wins
Zeros (1M) 0.93× FrankenNumPy wins
Arange (1M) 0.99× Parity
Exp (100K) 1.02× Parity
Argsort (100K) 1.02× Parity
RFFT (1M) 1.08× Parity
Var (1M) 1.13× Parity
Dot (10K) 1.47× Near-parity
Sum (1M) 1.58× Near-parity

What this table measured. The rows marked as wins were produced after commit c1d66c3c (2026-05-25) switched add, multiply, sum, std, var, sort, argsort, matmul, exp and rfft to pass straight through to NumPy, forty minutes before the table was published, so those ratios are NumPy timed against NumPy plus wrapper overhead and the sub-1.0 values are noise. The table is kept as the parity-era record; it is not a measurement of the FrankenNumPy engine, and it does not meet the "no NumPy fallback for the FNP side" rule stated below. The only checked-in cross-engine baseline of the Rust core (artifacts/baselines/cross_engine_benchmark_v1.json, 2026-04-10) showed elementwise ops 23-54x slower at that time; the v0.2.0 campaign table above is the current picture.

Benchmark methodology

The cross-engine benchmark (run_cross_engine_benchmark.sh) is pedantic by design, so that ratios published in this README are reproducible:

  • Workload definition. Every workload (mul_f64_large, axis_reduction_axis0_3d, fft_pow2_1024, ...) is defined in artifacts/contracts/cross_engine_benchmark_workloads_v1.yaml with its operation name, input shape, dtype, fixed seed, and warmup/measurement iteration counts.
  • Same inputs both engines. Inputs are constructed once from the fixed seed and passed to both NumPy and FrankenNumPy. There is no per-engine input randomness.
  • Per-workload statistics. For each workload we run a warmup pass (≥ 100 iterations on small ops, scaled down for slow ones), then a measurement pass, then record p50 / p95 / p99 latency and total bytes processed. Ratios reported in the table are p50 ratios.
  • Environment fingerprint. Every baseline records a fingerprint: hostname, CPU model, core count, cache sizes, kernel version, Rust toolchain version, NumPy version, BLAS backend NumPy linked against (numpy.show_config()), and the workload YAML hash. Two baselines are only compared when their environment fingerprints match.
  • No NumPy fallback for the FNP side. When we benchmark a tier-1 wrapper (see Python attribute resolution model), the benchmark forces the fast path: a fast-path-skipped run would be silently measuring numpy, not FrankenNumPy, and would be discarded.
  • Acceptable-degradation gates. The G7 performance budget gate doesn't gate the ratio against NumPy; it gates the ratio against the previous commit, built and measured in the same CI job on the same runner. A decidable median regression above 7% on a sentinel workload fails the gate; nothing is written back as a baseline. The per-round measurements, the report and both binaries' SHA-256 are uploaded as the run's g7-performance-budget-ab artifact.

The published cross-engine baseline is dated 2026-05-25. A refresh after each major performance lever lands is part of the optimization governance pattern: baseline → profile → single lever → conformance check → re-baseline.


This section in the README on GitHub