Lane-mp3-perf r1 report — encode 0.052 -> 0.881 of the incumbent, target met
Browse files at this commitc66696ac5d0c2152cd3cf684ad128bc068127a22Parent: 5081e9a- docs
- lane-mp3-perf r1 report — encode 0.052 -> 0.881 of the incumbent, target met
1 changed file +88 -0
- lanes/mp3perf-r1.report.md +88 -0
lanes/mp3perf-r1.report.mdadded+88 -0
| @@ -0,0 +1,88 @@ | ||
| 1 | +# lane-mp3-perf — ec-mp3 encode speed vs the incumbent MP3 encoder 0.6.1 (r1) | |
| 2 | + | |
| 3 | +Charter: close the ec-mp3 ENCODE gap (the seat went out at ~7-8x realtime stereo | |
| 4 | +CBR against the incumbent's 147-283x single-thread; a 2 h film's stereo track | |
| 5 | +cost ~17 min of export wall). Branch lane-mp3-perf off 0d81d6c5. | |
| 6 | +Worktree-only; no merges, no pushes. | |
| 7 | + | |
| 8 | +## Method | |
| 9 | + | |
| 10 | +- A/B harness: `~/Documents/Code/Rust/mp3-perf-ab` (scratch crate outside the | |
| 11 | + family workspace, opus-perf precedent — it links the crates.io incumbent | |
| 12 | + 0.6.1 beside ec-mp3 by path into this worktree; the workspace shim carries | |
| 13 | + the same crate name so this cannot live inside). | |
| 14 | +- PCM: deterministic synthesized music (3 s stereo 44.1 k), a 1 kHz tone | |
| 15 | + (3 s mono 48 k), 30 s of the 44.1 k stereo music the family gates use, and | |
| 16 | + the crate's own mp3src fixtures — all cached as raw interleaved f32, both | |
| 17 | + engines fed byte-identical bytes in-process. | |
| 18 | +- Protocol per row: one warm-up each side, 7 alternating rounds (A/B and B/A | |
| 19 | + by round parity), min per side, /proc/loadavg per round. Single-threaded | |
| 20 | + both sides (the incumbent is thread_local-only). | |
| 21 | +- Quality gate per commit: the crate's own release suite (21 lib + decode | |
| 22 | + matrix + encode matrix) green, every fixture decoded through ffmpeg, and | |
| 23 | + aligned correlation vs source compared to the pre-change build on the same | |
| 24 | + PCM. Byte-identity of the encoded stream was the stronger check wherever it | |
| 25 | + held (it held everywhere except where noted). | |
| 26 | + | |
| 27 | +## Baseline (0d81d6c5, load 1.8-2.2) | |
| 28 | + | |
| 29 | +| row | ec-mp3 | incumbent | ratio | | |
| 30 | +|---|---|---|---| | |
| 31 | +| music3s cbr192 | 239.0 ms / 12.6x | 23.0 ms / 130.6x | 0.096 | | |
| 32 | +| real30s cbr192 | 3661.2 ms / 8.2x | 190.1 ms / 157.8x | 0.052 | | |
| 33 | +| tone48k cbr192 mono | 106.3 ms / 28.2x | 7.8 ms / 385.6x | 0.073 | | |
| 34 | +| real30s vbr | 7540.3 ms / 4.0x | 189.5 ms / 158.3x | 0.025 | | |
| 35 | + | |
| 36 | +(ec VBR = quality 0.5 on its own scale; the incumbent's VBR takes a target | |
| 37 | +mean kbit/s, so that row passes 190 on its side — roughly rate-matched.) | |
| 38 | + | |
| 39 | +## Profile at baseline, and what each step did | |
| 40 | + | |
| 41 | +Order of attack was measured, not guessed: 45% BitWriter per-bit loops, 22% | |
| 42 | +code_spectrum's Vec<bool> round-trip, 10% libm cos in the MDCT, ~12% powf/exp2. | |
| 43 | + | |
| 44 | +| commit | change | stereo CBR | VBR | quality | | |
| 45 | +|---|---|---|---|---| | |
| 46 | +| 1fbe9240 | word-buffered BitBuf; rate loop prices gains by Huffman cost alone, materialises bits once | 18.2x / 0.115 | 10.6x | byte-identical, all 8 | | |
| 47 | +| c056aa4d | 3/4-power as cube+two sqrts; band gains hoisted per band | 21.1x / 0.134 | 13.0x | corr equal to 6 decimals on all 8; 7/8 byte-identical (music3s flips one ulp-boundary line) | | |
| 48 | +| f51fef8f | forward-MDCT cosine kernels tabulated (LazyLock f32, f64 accumulation kept) | 37.3x / 0.235 | 17.8x | byte-identical, all 8 | | |
| 49 | +| 891dd0b2 | best_table_cost: one walk over the region accumulates every candidate table | 43.7x / 0.278 | 20.9x | byte-identical, all 8 | | |
| 50 | +| 46a73869 | gain search brackets by doubling stride + bisection (was a one-step walk; instrumentation showed ~31.5 quantise+plan evaluations per granule) | 96.0x / 0.608 | 52.4x | 7/8 byte-identical; music3s as above | | |
| 51 | +| bdb12e0c | cursor-based push drain (was quadratic memmove), deinterleave scratch, no per-granule pending clone | 109.8x / 0.693 | 55.7x | byte-identical, all 8 | | |
| 52 | +| e51d830d | quantise_span: the level curve eight lanes wide through wide::f32x8 | 127.9x / 0.819 | 67.5x | byte-identical, all 8 | | |
| 53 | +| 0266ddcb | region walk: zero-pair fast path, per-candidate range feasibility upfront | 139.2x / 0.886 | 74.3x | byte-identical, all 8 (music3s inherited) | | |
| 54 | + | |
| 55 | +## Final table (0266ddcb, local, loadavg 2.9-3.6, min-of-7 alternating) | |
| 56 | + | |
| 57 | +| row | ec-mp3 | incumbent | ratio | baseline | | |
| 58 | +|---|---|---|---|---| | |
| 59 | +| real30s cbr192 | 214.5 ms / 139.9x | 189.0 ms / 158.7x | **0.881** | 0.052 | | |
| 60 | +| music3s cbr192 | 47.0 ms / 63.8x | 22.7 ms / 132.3x | 0.482 | 0.096 | | |
| 61 | +| real30s vbr | 403.7 ms / 74.3x | 189.2 ms / 158.5x | 0.469 | 0.025 | | |
| 62 | +| tone48k cbr192 mono | 38.0 ms / 79.0x | 7.8 ms / 382.8x | 0.206 | 0.073 | | |
| 63 | + | |
| 64 | +Target ≥0.7 of the incumbent single-thread (105x+ RT stereo CBR): **met** on | |
| 65 | +the 30 s music row, 0.881; the 2 h-film export cost drops from ~17 min to | |
| 66 | +~2.5 min of wall. Quality holds: every fixture's decoded correlation equals | |
| 67 | +the pre-change build to six decimals (music3s-cbr192: 0.999998 on both; its | |
| 68 | +stream moved by ulp-boundary level flips when the gain search and the f64→ | |
| 69 | +scalar-curve change landed, both gated above). | |
| 70 | + | |
| 71 | +## What remains, honestly | |
| 72 | + | |
| 73 | +- **VBR 0.469.** VBR re-codes the whole frame per bitrate candidate (bisection | |
| 74 | + over the legal-rate table), so it pays the CBR cost several times. The same | |
| 75 | + kernels are what it spends; a candidate-count reduction (start from the | |
| 76 | + last settled index with a tighter bracket) is the next lever and is | |
| 77 | + measurable with the existing harness. | |
| 78 | +- **Mono 0.206.** The incumbent's mono path is disproportionately fast | |
| 79 | + (385x vs its 158x stereo); ours pays the same per-granule costs either way. | |
| 80 | + Dense-content stereo — the seat the product pays — is where the work went. | |
| 81 | +- **Threading evaluated, declined.** Frame-level parallelism is constrained | |
| 82 | + by the bit reservoir (a frame's budget depends on bytes actually consumed | |
| 83 | + by predecessors) and the one-granule look-ahead; an API-compatible shape | |
| 84 | + would pipeline one frame behind, and with the single-thread target met the | |
| 85 | + added determinism surface buys nothing this round. | |
| 86 | +- Cross-machine final table on an idle server not run: both engines share one | |
| 87 | + process here, so every ratio above is already same-machine/same-load; a | |
| 88 | + quiet-box pass would tighten the absolute x-realtime numbers only. |