Repository navigation
Description
Follow-on from #4138, which measured that minimp3-fixed — the build that ships on every embedded target — is ~1.59x slower than the Helix decoder it replaced, while being 20.4 dB more accurate than it.
We are paying for quality nobody asked for, on the parts least able to afford it.
Proposal: two modes
| mode | target accuracy | target speed | who |
|---|---|---|---|
| HQ (today's decoder, unchanged default where affordable) | 123.24 dB | 1.59x Helix | hosts, ESP32-S3/P4, anything with SIMD or headroom |
| Fast (new) | ≥102.87 dB (Helix parity) | ≈1.0x Helix | ESP32-C6/C3/H2 and other non-SIMD 32-bit parts |
The accuracy budget is the whole point of the split:
123.24 dB minimp3-fixed today (HQ)
102.87 dB Helix — the parity bar
60.00 dB ISO limited-accuracy floor
There is 20.4 dB of headroom between what we ship and what Helix managed, and 63 dB above the ISO floor. Fast mode spends part of the first number and must not touch the second.
Why this matters on the C6
bash autoresearch esp32c6 --mp3 on an ESP32-C6 at 160 MHz:
decode 155810 us for 235101 us of audio -> 1.51x real time
One stereo 44.1 kHz stream consumes two thirds of a core. At Helix parity that becomes roughly 2.4x, which is the difference between "MP3 plus a demanding LED driver" working and not.
Known-dead path: do not re-run this
A naive 16-bit MAC has already been measured (#4108) and it fails outright:
| variant | PSNR |
|---|---|
| 32-bit MACs (ships today) | 123.24 dB |
| 16x16 MACs simulated | 44.37 dB |
| Helix | 102.87 dB |
| ISO floor | 60 dB |
Keeping only the top 16 bits of the wide operand in mp3d_mulshift (DCT-32) and mp3d_synth_pair (polyphase) costs ~79 dB — 15 dB below the ISO floor, not merely below Helix. The coefficients there are already 16/17-bit (29, 213, 459, 2037, 5153, 6574, 37489, 75038, 64019), so the Q26 samples are the wide side and truncating them is what destroys it.
So a blanket fp<8,8> / Q8.8 across the polyphase is not viable. Anything in that direction needs to be measured against l3-hecommon.bit before it is built on.
Directions that look better
1. Copy what Helix actually does. Helix reaches 102.87 dB using MULSHIFT32 — keep the high 32 bits of a 32x32 product — alongside MADD64 where it needs the width. minimp3-fixed instead accumulates in int64 throughout and saturates via mp3d_sat64. Trading full 64-bit accumulation for a high-half multiply in the polyphase is the single most direct route to Helix parity, and Helix is the existence proof that it lands above 100 dB.
2. Spend the headroom selectively, not uniformly. The stage timings say the cost is not evenly spread. Per-frame host medians: synthesis 20,598 ns, huffman 7,373 ns (float) vs 12,134 ns (fixed), imdct 3,440 ns. Synthesis dominates and is the right place to trade precision; huffman is integer work in both builds and its fixed-build regression is unexplained (#4138) — that is a bug to find, not precision to spend.
3. Reduced intermediate width, not reduced operand width. 24-bit or Q1.30 intermediates in the polyphase keep the wide operand intact while shrinking the accumulator, which is a different trade from the one already measured to fail.
4. fl::fixed_point templating. If the DSP is parameterised on a fixed-point type, HQ and Fast become instantiations rather than a fork, and the conformance suite can run both. This was floated earlier in the MP3 work and is the cleanest structure if the arithmetic change is otherwise viable.
Acceptance
- Fast mode scores ≥102.87 dB on
l3-hecommon.bit(Helix parity) and clears the 60 dB ISO floor on all 83 conformance vectors, fixed and float - Fast mode is ≤1.1x Helix in host cycles on the
ci/codec_cpu/driver.cppcorpus - HQ mode is bit-identical to today's decoder — no accidental regression of the default
- On-device:
bash autoresearch esp32c6 --mp3reports ≥2.0x real time in Fast mode, still bit-exact against a host-generated fixture for that mode - Both modes carry host baselines in
codec_cpu_trend.json(todayminimp3-fixedhas none — see perf(mp3): fixed-point minimp3 is ~1.6x slower than the Helix it replaced, and nothing gates it #4138)
Notes
- Mode selection should follow the existing pattern: decided in
minimp3.h, not by a per-TU build flag.MINIMP3_SCRATCH_SIZEdepends on the DSP choice, and a flag passed to one translation unit and forgotten in another fails as a malloc assertion far from MP3. - Measure on a 32-bit target, not just the host. fix(mp3): signed overflow (UB) in fixed-point mp3d_synth_pair on malformed input #4133 cost +78% instructions on armv7m/riscv32/i386 and exactly 0% on x86-64 — host ratios can be blind to the thing being optimised.
- Anything general here should go upstream to lieff/minimp3; the fixed-point port is a FastLED fork.
Background, method and recovered Helix baselines: agents/docs/mp3-decoder-performance.md and #4138.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Sep 1, 2026
The gap is ~18%, not ~59% — acceptance criteria need revising
See #4138's correction. The measurement this issue was written against was taken on a machine under load average 12. Clean re-measurement, three consecutive trials with pinned affinity and 30-run medians:
Production flags land somewhere around 1.2–1.45x and are still too noisy on this host to pin down.
What this changes
The premise stands — the shipping fixed-point build is slower than the decoder it replaced, and it does carry 20.4 dB of accuracy nobody asked for. A Fast mode is still worth having.
But the size of the prize is much smaller than stated. Closing ~18% is a different engineering proposition from closing ~59%, and it changes the cost/benefit of every option listed:
fl::fixed_pointtemplating) should probably wait until the huffman regression is understood, in case it closes the gap on its own.Revised acceptance
Superseding the criteria in the body:
l3-hecommon.bitcodec_cpu_trend.jsonThe known-dead 16-bit path (44.37 dB, 15 dB below the ISO floor) is unaffected by the correction and still should not be re-attempted.
perf(mp3): find the gap with Callgrind -- saturation is 24% of the de…
zackees commentedon Sep 1, 2026
Callgrind says the gap is one line of C
Switched from cycles to Callgrind instruction counts, on the reasoning that this issue has now had its premise corrected twice off noisy cycle data. Instruction counts are deterministic: the Helix figure measured today lands 0.18% from the baseline recorded a year ago on different hardware.
Scalar (
-DMINIMP3_NO_SIMD),-O2with inlining, 892 frames:Correcting the correction
My earlier "~18%" was measured at
-O1 -fno-inline. That is a real number for a configuration nobody ships. The same comparison:-O1 -fno-inline-O1 -fno-inline-O2inlinedHelix gains more from inlining than minimp3 does (2.07x vs 1.86x reduction), so the gap widens with optimisation. The audit's
-fno-inlineflags understate it. Quote the-O2scalar figure.So the original 1.59x was right by accident — from a loaded machine with SIMD on — and my correction to 1.18x was right about the method but measured the wrong build.
Where it is
mp3d_synth_granuleClipToShort+ clip helpermp3dec_decode_frame_rL3_imdct36Total excess is 130.7M. Synthesis alone differs by 135.7M — synthesis is the gap; everything else roughly cancels.
And inside synthesis:
mp3d_sat64saturates every intermediate in the polyphase. Helix does not: it truncates viaMULSHIFT32in the inner loop and clips once, at output, inClipToShort. That is a design difference, not a micro-optimisation, and it is roughly two thirds of the excess.What this changes for this issue
The HQ/Fast split may not be needed. This is not a precision-vs-speed trade — it is a redundant clamp on every intermediate. If synthesis can accumulate without per-step saturation and clip once at output, the gap closes at no accuracy cost at all, and both the 123.24 dB and the speed are kept.
Revised first task:
int64and the coefficients are 16/17-bit, so the true sum may not need clamping until it narrows to output — the same argument fix(mp3): signed overflow (UB) in fixed-point mp3d_synth_pair on malformed input #4133 used for widening rather than saturating there.Do not confuse this with #4127
#4127 fixed the clamp's bounds — it was pinning to ±1.0 instead of the int32 range — and was worth 81 dB. The cost here is evaluating the clamp per intermediate at all. Any change must keep #4127's bounds and the 83-vector ISO suite green; that suite exists precisely to catch a regression there.
Method and full attribution:
agents/docs/mp3-decoder-performance.md.zackees commentedon Sep 1, 2026
Clarification on the ratio direction. The tables above report
backend / helixin instructions executed, so higher is worse.1.59xmeans minimp3-fixed does 59% more work than Helix — it is the slower one. Written as a bare multiplier that reads naturally as "1.59x faster", which is the opposite of what it says.The audit now prints the direction with the number (
sense=slower:pct=59) so this cannot be misread from CI output.perf(mp3): the DCT saturation defends exactly one malformed vector
perf(mp3): measure both decoders on the C6 -- the gap is 4x, not 1.59x
fix(lint): restore Helix's banned-header exception with the decoder
zackees commentedon Sep 2, 2026
On-device: the gap is 4x, not 1.59x
Measured on an ESP32-C6 at 160 MHz, both decoders compiled into one firmware and timed in the same run with no reflash between them:
The host understated it by two and a half times. Nothing in the x86 profile hinted at 4x, which is the whole argument for having put Helix back in the tree.
Likely cause is what #4133 already demonstrated: minimp3-fixed's arithmetic is dense with
int64—mp3d_sat64, the polyphase accumulators,mp3d_mulshift— and an int64 operation is a register pair plus a carry chain on a 32-bit core while being free on x86-64. Helix was written for 32-bit MCUs and usesMULSHIFT32(32x32 keeping the high half) throughout.Two wrong answers preceded this one, both from timing something without checking it did the work. The first run said 4.32x — it was timing minimp3 over 11 frames against Helix over 8, because Helix does not decode Layer I. The comparison is now Layer III only on both sides, and the runner suppresses the ratio outright if frame and sample counts differ. Residual bias is quantified: minimp3's leg computes the fixture checksum and Helix's does not, ~0.3%, biasing against minimp3.
The target, restated
Saturation analysis from the previous comment still holds and is now much more valuable:
mp3d_sat64is 24.5% of the decode on x86-64 and 32.4% ofmp3d_DCT_IIstatically on riscv32l3-nonstandard-big-iscfSo on conformant input, saturating and not saturating produce identical output. The trade is malformed-input robustness against a third of the DCT-32 — not accuracy against speed.
Revised acceptance
Superseding both earlier sets:
bash autoresearch esp32c6 --mp3reports the on-device ratio directly now.l3-hecommon.bit— the 20.4 dB advantage over Helix is the reason to prefer minimp3 and must not be spentl3-nonstandard-big-iscfstays bounded — no wrap to a sign-flipped full-scale sampleOrder of work
int64use on 32-bit paths generally —mp3d_mulshiftand the polyphase accumulators are the other half of the arithmetic.An HQ/Fast split now looks unnecessary. If the clamp is redundant on conformant input, removing it costs no accuracy at all, and there is no trade to expose as a mode.
perf(mp3): drop the DCT/IMDCT butterfly clamp -- 28% faster on the C6
feat(math): add fl::math::mulshift32 with a pinned instruction shape
feat(math): add fl::math::mulshift32 with a pinned instruction shape
perf(mp3): force-inline the hot leaf helpers -- 50% faster on the C6
perf(mp3): route mp3d_mulshift through fl::math::mul_shift_round32
perf(mp3): unsaturated narrow and a mono polyphase; add the measureme…
perf(mp3): restructure the polyphase lane loop -- 12% faster on the C6
perf(mp3): profile at -Os, and make the inline policy switchable
perf(mp3): fixed-point decoder is 3.5x faster on an ESP32-C6
fix(ci): the RunningProcess migration broke three tools; measure, don…
zackees commentedon Sep 5, 2026
Closing as superseded. The comment trail on this issue retired its own premise: the fixed-vs-Helix gap turned out to be per-intermediate saturation cost, not a precision trade, so there is nothing to expose as a Fast mode. The work then landed without a mode split.
Against the final revised acceptance list:
bash mp3measureruns both decoders in one firmware and reports the ratio.l3-hecommon, the 83-vector ISO floor,l3-nonstandard-big-iscfbounded, fix(mp3): fixed-point dequant clamps samples to 1.0, losing 81 dB on l3-si_huff #4127 clamp bounds: all kept and checked on every run.The only unmet item is the 1.1x stretch goal. That is ordinary optimisation work in
minimp3_synth_fixed.h, not a feature request, and does not need this issue open. Leftover housekeeping from this thread and #4138 is collected in #4155.🤖 Generated with Claude Code
https://claude.ai/code/session_01XQyTuAVs4tK9pDcxAZVqVe