SPB Git

Repository Public MIT

performance.md 6.9 KB

# Performance

All numbers on this page were measured; none are estimates. They come from Benchmarks/ (swift run -c release orix-bench), a command-line harness that calls the engine packages directly. The raw output of the last run is in benchmark-results.md.

What these numbers are: engine time on the development Mac named in the table header, release build, single thread, median wall-clock of repeated runs. What they are not: on-device measurements. An iPhone is slower than this Mac by a device-dependent factor; cold launch, memory and battery were not measured (see "Not measured").

# Engine measurements

Machine: Apple M5 Max, 18 cores, macOS Version 27.0 (Build 26A5425a) Build: release, single thread, wall-clock median of repeated runs

Benchmark Median Best Runs Notes
Parse + evaluate 25 × 4 38.8 µs 17.8 µs 2000
Parse + evaluate 0.1 + 0.2 (exact rational) 50.9 µs 25.1 µs 2000
Parse + evaluate sin(30)^2 + sqrt(2) * ln(10) 92.7 µs 42.6 µs 2000
Full run with explanation and verification (1234.5 + 6) * 7 / 8 - 9^2 99.8 µs 53.0 µs 2000
100! exact (158 digits) 82.8 µs 36.7 µs 2000
2000! exact (5 736 digits) 689.1 µs 479.4 µs 351
sum(1/k^2, k, 1, 1000) exact rational sum, falls back to double past 8192 bits 152.50 ms 145.32 ms 7
integral(exp(-x^2), x, -inf, inf) adaptive quadrature 80.4 µs 39.1 µs 2000
Compiled function: 100 000 evaluations of sin(x)² + e^(−x/3)·√ x 4.10 ms 3.73 ms
Determinant 20 × 20, exact rational arithmetic 8.81 ms 8.11 ms 28
Determinant 50 × 50, exact rational arithmetic (decimal entries) 437.67 ms 410.47 ms 5
Determinant 50 × 50, floating point 10.82 ms 9.44 ms 23
Inverse 50 × 50, floating point (with residual check) 27.33 ms 25.45 ms 9
Product 50 × 50 · 50 × 50, floating point 13.52 ms 12.51 ms 18
Eigenvalues 50 × 50 (LAPACK dgeev) 4.14 ms 3.66 ms 59
Workspace: open and compute 501 linked cells 289.38 ms 281.07 ms 5
Workspace: move a slider that 500 cells depend on 1.21 s 1.08 s 5
Workspace: edit a leaf cell (1 cell recalculated out of 501) 14.04 ms 12.39 ms 16
Workspace: move a slider that 500 floating-point cells depend on 17.48 ms 14.85 ms 14
Workspace: move the DiscountRate slider of a 14-cell NPV sheet 1.59 ms 1.08 ms 119
Workspace: export 501 cells to LaTeX 680.08 ms 466.75 ms 5
Mortgage payment (Canadian convention) 17.6 µs 16.1 µs 2000
Amortization schedule, 300 payments, cent-exact 2.82 ms 1.59 ms 45
IRR of 241 cash flows (all real roots searched) 17.5 µs 16.8 µs 2000
Black–Scholes–Merton price 33.1 µs 30.6 µs 2000
Implied volatility 21.0 µs 19.2 µs 2000
American put, binomial tree, 1 000 steps 529.8 µs 503.6 µs 224
Monte Carlo, 1 000 000 normal trials, seeded 561.69 ms 519.90 ms 7
Multiple regression, 10 000 rows × 3 predictors, with diagnostics 2.21 ms 1.46 ms 48
Quantile of 10 000 values 586.7 µs 540.2 µs 84
Student t quantile (inverse incomplete beta) 2.0 µs 1.9 µs 2000
Graph: sample sin(x) at 1200 × 800 with discontinuity detection 177.5 µs 141.9 µs 774
Graph: sample tan(x) at 1200 × 800 with discontinuity detection 683.8 µs 446.8 µs 207
Graph: sample 1/x at 1200 × 800 with discontinuity detection 236.8 µs 175.5 µs 690
Graph: sample sin(100x) at 1200 × 800 with discontinuity detection 2.26 ms 2.03 ms 26
Graph: implicit curve x² + y² = 25 at 1200 × 800 5.75 ms 3.85 ms 19
Graph: 60 × 60 surface mesh of sin(x)·cos(y) with normals 670.5 µs 658.1 µs 172
Unit conversion, exact decimal (mi → km) 2.4 µs 2.3 µs 2000

# Reading the results

  • Everyday arithmetic is tens of microseconds including parsing. The figure includes the start of a dedicated large-stack thread for each evaluation (see DeepStack), which is most of the cost of a trivial expression.
  • Exact arithmetic costs what it computes. 2000! (5 736 digits) takes well under a millisecond. Sums of many fractions with unrelated denominators grow quickly: sum(1/k², k, 1, 1000) is exact until the fraction passes 8192 bits, then continues in floating point with a precision note; it is the slowest expression in the table and runs off the main thread.
  • Linear algebra: floating-point 50 × 50 operations take milliseconds. Exact 50 × 50 elimination on decimal entries takes around a second because every pivot step reduces large fractions; it is cancellable and off the main thread.
  • Workspace: a slider on a typical sheet (the 14-cell NPV model) recalculates in under 2 ms, well inside a 120 Hz frame. A 500-cell floating-point dependency chain recalculates in one to two frames. The pathological case — 500 cells that each compound an exact rational, so that every value has thousands of bits — takes about a second per change; it is listed in Known Limitations.
  • Graphing: sampling a function across 1200 pixel columns with discontinuity detection takes a fraction of a millisecond; a function that oscillates faster than the screen can show is detected and drawn as a band in about 2 ms.

# Optimisations made from profiling

Finding (from the benchmark and sample) Change
Verification notes built their message text inside arithmetic inner loops The text is now built only when the note is first recorded
Moving a workspace slider re-parsed every cell A fast path updates the parameter's literal and re-evaluates only its dependents
The dependent-cell search was quadratic Reverse index + breadth-first closure
A "floating-point" matrix benchmark was in fact exact (decimal literals are exact by design) The benchmark now measures both cases separately
Long sums overflowed small thread stacks Evaluation runs on a 64 MB stack; chains are bounded at 1000 terms; long chains compile to loops

# Responsiveness design

  • Committed evaluations, live previews, binomial trees, Monte Carlo runs, bootstrap, ODE solves, sweeps and graph sampling run off the main actor; the main actor only applies results.
  • Latest-wins cancellation is used wherever input changes faster than results (previews, sliders, pan and zoom).
  • Graph gestures redraw immediately from the previous samples and refine when new samples arrive.

# Not measured

Cold launch time, memory footprint, energy use and frame rate on physical devices. No physical device was connected during development; these must be measured with Instruments on real hardware before public release.

Files main
Menu

Theme