SPB Git

Repository Public

performance.md 5.1 KB

# Performance

This chapter reports what was measured, how, and on what. The figures describe one machine on one day; they are measurements, not promises. Run sonata benchmark to get yours.

# Protocol

  • Machine. MacBook Pro, Apple M5 Max, 18 cores, 48 GB, macOS 27.0.
  • Build. Release build of the command-line tool (cargo build --release), measured 2026-11-24.
  • Method. sonata benchmark --seconds 4. Each case compiles a composition, prepares it and drives the real-time processor on one thread in blocks of 128 or 256 frames at 48 kHz, for 4 seconds of audio after a warm-up. No audio device is involved: the engine is timed alone. The engine measures the duration of every callback itself.
  • What is reported. The time available for a block (the budget: 2 667 µs for 128 frames at 48 kHz), the mean, median (p50), 99th percentile (p99) and maximum time actually taken, the p99 as a percentage of the budget, and the number of callbacks that took longer than their budget (missed). Percentiles are upper bounds of 5 µs buckets.

The percentiles matter more than the mean: one late block is a click, however fast the average.

# Voices

Each case holds N notes at once on one instrument for the whole measurement.

Case Block Budget Mean p50 p99 Max p99 / budget Missed
SynthLead × 1 128 2 667 µs 6 µs 10 µs 10 µs 28 µs 0.4 % 0
SynthLead × 16 128 2 667 µs 64 µs 60 µs 120 µs 132 µs 4.5 % 0
SynthLead × 64 128 2 667 µs 209 µs 210 µs 240 µs 294 µs 9.0 % 0
SynthLead × 128 128 2 667 µs 402 µs 405 µs 445 µs 550 µs 16.7 % 0
SynthLead × 256 128 2 667 µs 788 µs 790 µs 865 µs 1 149 µs 32.4 % 0
SynthLead × 256 256 5 333 µs 1 547 µs 1 540 µs 1 830 µs 2 090 µs 34.3 % 0
GrandPiano × 1 128 2 667 µs 8 µs 10 µs 15 µs 40 µs 0.6 % 0
GrandPiano × 16 128 2 667 µs 63 µs 60 µs 115 µs 131 µs 4.3 % 0
GrandPiano × 64 128 2 667 µs 221 µs 220 µs 310 µs 398 µs 11.6 % 0
GrandPiano × 64 256 5 333 µs 443 µs 440 µs 550 µs 719 µs 10.3 % 0

On this machine, 64 simultaneous piano voices use about a tenth of one core's time at 128 frames, and 256 synthesizer voices about a third, with no missed deadline in these runs.

What these figures do not say: they are for one thread, without a real audio device and without other programs competing for the processor; they cover two instruments, without effects. Higher voice counts and other engines were not measured here, and nothing is claimed about them.

# A complete piece

sonata benchmark Examples/multitrack_band.sonata --seconds 8: six instrument tracks, two buses, compressors, a reverb, a delay, an equaliser and the limiter.

Block Budget Mean p50 p99 Max p99 / budget Missed
128 2 667 µs 42 µs 45 µs 60 µs 183 µs 2.3 % 0
256 5 333 µs 83 µs 85 µs 130 µs 243 µs 2.4 % 0

# Offline rendering

sonata render, release build, 24-bit WAV at 48 kHz, wall-clock time including compilation, measurement and writing the file:

Example Audio Render time Speed
aurora 4.4 s 0.05 s 95× real time
string_quartet 20.3 s 0.19 s 105×
mallet_phasing 17.5 s 0.14 s 128×
multitrack_band 12.8 s 0.21 s 62×
multitrack_band at 192 kHz 12.8 s 0.81 s 16×
ambient_drift 65.3 s 6.1 s 11×

ambient_drift is slow for a reason worth knowing: it uses the convolution reverb, which is by far the most expensive effect.

# Compilation

Time spent in each stage, from sonata inspect --json (release build, one run each):

Example Notes Lexing Parsing Semantics
aurora 8 57 µs 90 µs 156 µs
lofi_keys 157 67 µs 100 µs 253 µs
multitrack_band 162 86 µs 115 µs 399 µs

A piece of this size compiles in well under a millisecond, which is what makes compiling on every keystroke and hot reload practical. The console of the app shows the time of each compilation, and whether the result came from the cache.

# In the app

While a piece plays, the status bar shows the 99th percentile of the callback time and the number of voices; the mixer panel adds the median, the maximum and the number of overruns (callbacks that exceeded their budget). These are measured on the real audio device.

# Advice

  • The safety limiter and the meters cost almost nothing; leave them on.
  • A reverb on a bus, shared through sends, costs once; the same reverb on eight tracks costs eight times.
  • Convolution is expensive; the algorithmic reverb is not.
  • Long release times keep voices alive: 64 notes with a 5 s release can be 64 voices.
  • If you hear clicks, look at the overrun counter first. Zero overruns means the cause is in the music (a hard cut, a clipped level), not in the engine.
Files main
Menu

Theme