Skip to content

Execution plan: vendor minimp3, optimize to Helix parity, SIMD past Helix, delete libhelix_mp3 (phased, gated) #14

Closed
6 of 6 issues completed

Description

@zackees

Note

Execution plan for the work scoped in #13 (feasibility, with prototype) and motivated by #10 (license strategy: delete RPSL libhelix_mp3). Implementation PRs land in FastLED/FastLED; this issue is the phase tracker and can be transferred there when work begins. Each phase has an explicit exit gate — no phase starts until the previous gate is green in CI.

Job: vendor minimp3 → optimize to Helix parity → SIMD past Helix → lock in as the only MP3 backend

End state: src/third_party/minimp3/ (CC0, fixed-point capable, SIMD-accelerated) is FastLED's only MP3 decoder; src/third_party/libhelix_mp3/ (RPSL/RCSL) is deleted; the decoder is "locked": golden-tested, fuzzed, memory- and cycle-budgeted in CI so it cannot silently regress.

Ground-truth budgets to beat (Helix, from the #13 audit):

Metric Helix baseline
Working RAM ~24 KB heap (7 mallocs), tiny stack
Arithmetic ~55–75k multiplies/frame; 64-bit MACs only in polyphase
Realtime record ESP32 LX6/LX7, ESP32-C3, RP2040, Cortex-M3/M4 — proven
SIMD none anywhere — this is how we beat it

Phase 0 — Vendor & scaffold (no behavior change)

  • Vendor minimp3.h (+ minimp3_ex.h if needed for tests only) into src/third_party/minimp3/ following FastLED conventions: namespace fl { namespace third_party { … } } wrap, FL_NO_EXCEPT, MINIMP3_NO_STDIO, unity-build integration (_build.cpp.hpp → src/fl/build/third_party+.cpp).
  • Ship LICENSE (CC0-1.0) in the component dir + third-party manifest entry + per-file markers per the universal-marker policy (Strategy: project-agnostic GPL/free-software compatibility exception #10). Record upstream commit SHA in PROVENANCE-style note.
  • Dual-backend scaffold: src/fl/codec/mp3.h public API unchanged; backend selected at compile time — FASTLED_MP3_BACKEND_HELIX (default, unchanged) vs FASTLED_MP3_BACKEND_MINIMP3. The five-call Helix wrapper gets a sibling minimp3 wrapper (mp3dec_decode_frame maps 1:1; derive Mp3Info.version from the header bytes since mp3dec_frame_info_t lacks it).
  • Scratch off the stack immediately (prereq for everything): add mp3dec_decode_frame_r(dec, scratch, …) taking caller-provided mp3dec_scratch_t (16.3 KB); wrapper owns it heap-side. Upstream-friendly patch, kept as a minimal diff file against pristine upstream.
  • Golden harness v1 (host): one test binary builds Helix + minimp3-float backends; corpus from Feasibility: MINIMP3_FIXED_POINT — CC0 fixed-point minimp3 mode, golden-tested vs float, to replace RPSL libhelix_mp3 #13 (ISO 11172-4/13818-4 vectors, LAME synthetics incl. −60 dBFS sine, joint/intensity stereo, MPEG-2/2.5 low rates, free-format, VBR reservoir stress, resync garbage). Assert identical frame acceptance/sample counts between backends; PCM compared to ISO reference (both must pass limited-accuracy floor) and to each other (report-only PSNR — Helix vs minimp3 are different decoders; the hard golden gate arrives in Phase 3 as fixed-vs-float within minimp3).

Exit gate G0: minimp3-float backend passes the full corpus behaviorally on host CI (Linux + Windows + macOS); public Mp3 API byte-compatible; Helix default untouched; no src/ build regression on any platform (compile-only matrix incl. AVR/WASM).


Phase 1 — Memory audit (native host)

Build the measurement rig before optimizing anything. All instruments run on host; each produces a line in a versioned ledger.

  • Heap: route all codec allocations through an accounting allocator (fl:: hooks): bytes-current, bytes-peak, alloc-count, per-tag (decoder-state / scratch / stream-buffer). Cross-check with heaptrack or valgrind --tool=massif in the Linux CI job.
  • Stack: three instruments — (1) -fstack-usage + -Wframe-larger-than= on every codec TU (fails the build over budget); (2) watermark painting in the harness (fill a guard region with a pattern around the decode call, measure high-water); (3) static worst-depth estimate from .su files + call graph. Budget: ≤ 2 KB stack per decode call (everything big must be in owned state/scratch).
  • Static/flash: nm --size-sort / size on the codec object; table ledger (every const table, bytes, which stage). Fixed-point tables added in Phase 3 must be itemized here.
  • Ledger: codec_memory_ledger.md checked in, machine-parsed in CI; a PR that regresses any figure > 2% fails unless the ledger is deliberately updated in the same PR (fail-closed, same philosophy as the license tooling).
  • Record Helix's numbers with the identical rig (it's in-tree — same allocator hooks, same watermarking) so parity claims are apples-to-apples.

Targets: working RAM (persistent + scratch + stream buffer) ≤ 24 KB (parity), stretch ≤ 20 KB; flash tables ≤ Helix's table footprint + 20%.

Exit gate G1: ledger populated for Helix and minimp3-float; CI regression gate live; scratch-off-stack verified by watermark (< 2 KB stack).


Phase 2 — CPU profiling audit (native host)

Host cycles don't predict MCU cycles — so the rig measures three tiers, from portable to µarch-specific:

  • Tier 1 — arithmetic-op ledger (the MCU-honest metric): instrument the multiply primitives (MULSHIFT32, 64-bit MAC, float mul in the float build) with audit-build counters. Decode the corpus; report exact multiplies/frame and MACs/frame per stage, for Helix and minimp3 alike. This is the metric parity is defined on (Feasibility: MINIMP3_FIXED_POINT — CC0 fixed-point minimp3 mode, golden-tested vs float, to replace RPSL libhelix_mp3 #13 projection: 55–75k/frame) and it is host-independent.
  • Tier 2 — host attribution: perf stat (cycles, instructions, IPC, branch misses) + valgrind --tool=callgrind per-function attribution; per-stage wall-time via the MINIMP3_STAGE_DUMP hooks' timer variant. Pinned governor, deterministic corpus, N=30 runs, report medians. Trend file (codec_cpu_trend.json) tracked in CI; ±5% regression gate.
  • Tier 3 — codegen inspection for MCU ISAs: cross-compile the codec TU with -Os for xtensa-esp32-elf, riscv32-esp-elf, arm-none-eabi -mcpu=cortex-m0plus and -mcpu=cortex-m4; objdump the inner loops (polyphase, DCT32); record inner-loop instruction counts in the ledger. Catches "host looked fine, M0+ emits a 6-instruction libcall per MAC" early — no hardware needed.
  • Baseline all three tiers for Helix with the same rig.

Exit gate G2: all three tiers automated in CI; Helix baseline recorded; minimp3-float baseline recorded (expect it to lose badly — that's the point of the ledger).


Phase 3 — Fixed-point conversion to parity (the #13 staged plan, run under the audit rigs)

Stage order and design per #13 (synthesis back-end → IMDCT/antialias → Huffman/dequant/scalefactors → stereo + guard-bit tracking end-to-end; MINIMP3_ONLY_MP3 for v1). Clean-room rules from #13 §Clean-room apply (Helix = ideas only; tables regenerated from ISO formulas; generator scripts committed).

  • Golden gate hardens: fixed-vs-float within minimp3 — PSNR ≥ 90 dB and ≤ 8 LSB on every corpus file; −60 dB signal-relative gate ≥ 55 dB; per-stage MINIMP3_STAGE_DUMP epsilons; differential fuzz (both modes agree accept/reject + PCM, ASan/UBSan clean).
  • Each converted stage must land with: golden green, memory ledger delta itemized, op-ledger delta itemized.
  • Scalar optimization pass to close any gap to Helix parity: early-terminating polyphase multiplies (Helix's pre-shifted-coefficient concept), table layout for cache/flash-line locality, sync-scan cost reduction, buffer reuse between granules.

Exit gate G3 ("Helix parity"): on the op-ledger, multiplies/frame ≤ 1.1× Helix; working RAM ≤ 24 KB; stack ≤ 2 KB; all golden + fuzz gates green; Tier-3 inner-loop instruction counts within 1.2× of Helix's on all four ISAs. One on-target spot-check (ESP32 + RP2040 cycles/frame) to validate that the host proxies track reality — the only non-host step in the audit plan, run once at this gate.


Phase 4 — SIMD: beat Helix

Helix has zero SIMD — this is the phase that makes replacement strictly better, not just license-clean. Integer SIMD is bit-exact vs scalar fixed-point, so the golden gate here is exact equality, the strongest possible lock.

  • Host lanes first (prove the pattern where profiling is easy): SSE2 and NEON int32 paths for the dominant costs — polyphase (~37k MACs/frame), DCT32, IMDCT butterflies — following minimp3's existing float-SIMD scaffolding style (MINIMP3_NO_SIMD opt-out preserved).
  • Embedded flagship — ESP32-S3 PIE (128-bit vector unit): polyphase + DCT32 kernels via esp-dsp-style intrinsics/asm, guarded by chip detect at compile time.
  • Optional stretch: Cortex-M4/M7 DSP extension scheduling (SMULL/SMLAL pipelines; evaluate whether dual-16 SMLAD fits anywhere without precision loss — likely not for Q25 data; document the finding either way).
  • Every SIMD kernel: bit-exact vs scalar fixed on the full corpus (exact-equality golden), covered by the differential fuzzer, and toggleable at compile time.

Exit gate G4 ("faster than Helix"): host cycles/frame ≥ 1.5× faster than Helix-scalar on x86-64 and Apple/ARM CI runners; ESP32-S3 ≥ 1.3× faster than Helix on-target; no target anywhere slower than the scalar fixed path; bit-exactness green.


Phase 5 — Swap & lock-in

  • Flip the default: FASTLED_MP3_BACKEND_MINIMP3 becomes the default; Helix demoted to FASTLED_MP3_HELIX_LEGACY opt-in with a deprecation warning, for one minor release.
  • Run the Feasibility: MINIMP3_FIXED_POINT — CC0 fixed-point minimp3 mode, golden-tested vs float, to replace RPSL libhelix_mp3 #13 acceptance gate in full: golden suite green (ISO floor + internal PSNR gates), 72 h differential fuzz zero-divergence, on-target budgets (≤ 60% core on ESP32-C3@160 MHz and RP2040@133 MHz, ≤ 25% on ESP32@240 MHz for 44.1 kHz stereo 320 kbps), A/B listening sanity on demo content.
  • Delete src/third_party/libhelix_mp3/ + the .S srcFilter line in library.json; update third-party manifest, per-file markers, REUSE/SBOM output; note the removal in release notes ("FastLED no longer ships any RPSL/RCSL code").
  • Lock the decoder in place: golden corpus + fuzz smoke + memory ledger + cpu trend + bit-exactness gates all become required PR checks for any file under src/third_party/minimp3/ or src/fl/codec/mp3*; CODEOWNERS on those paths; the vendored diff-against-upstream kept minimal and documented.
  • Upstream PR to lieff/minimp3 (MINIMP3_FIXED_POINT + _r scratch API + SIMD lanes), CC0. If upstream is dormant, FastLED carries it in-tree as CC0 with the diff file as the contract.
  • Close the loop on the license side: update Strategy: project-agnostic GPL/free-software compatibility exception #10 (libhelix resolved — RPSL tree deleted), third-party audit row in the universal-marker migration, and LEGAL-REVIEW.md's standing-exception note for libhelix.

Exit gate G5 (done): Helix tree deleted on main; all lock gates required in CI; one release shipped with minimp3 default and no regression reports on the audio-reactive examples.


Sequencing, effort, risks

Dependencies: G0→G1→G2 can overlap (rigs are independent); G3 depends on G1+G2 (can't claim parity without both ledgers); G4 depends on G3 (SIMD over the fixed kernels); G5 depends on G4.

Effort: #13 estimated ~6 pw for the conversion; the audit rigs add ~1.5 pw; SIMD ~2 pw (host lanes + S3); swap/lock ~0.5 pw → ~10 person-weeks + 2 contingency.

Top risks (carried from #13, plus new): (1) dynamic-range corners in the guard-bit budget → −60 dB gates + stage hooks; (2) M0+ 64-bit-MAC budget → Tier-3 codegen ledger catches it at G2/G3, measured 32-bit-MAC fallback ready; (3) S3 PIE toolchain friction (intrinsics maturity) → treat S3 SIMD as the G4 flagship but allow G4-host to gate independently if PIE slips one milestone; (4) upstream divergence — pristine-upstream + minimal-diff discipline keeps rebases cheap.

Sub-issues

Sub-issues

6 of 6 Issues completed
Loading 6 sub-issues

Activity

  1. zackees commented on Aug 25, 2026

    @zackees
    MemberAuthor

    Closing as out of scope for the reusable license-text repository. This execution plan changes FastLED source and dependencies, while this repository publishes general-purpose license text and legal research. The issue history remains available for migration to the FastLED software repository.

  2. zackees commented on Sep 1, 2026

    @zackees
    MemberAuthor

    G5 has landed: libhelix_mp3 is deleted

    FastLED/FastLED#4056 merged as FastLED/FastLED@6990cdc3e4 (PR FastLED/FastLED#4112). src/third_party/libhelix_mp3/ is gone from master — 10,566 deletions — along with its LICENSE.txt, RPSL.txt and RCSL.txt. FastLED's MP3 support is now entirely CC0 (minimp3), which is the outcome this tracker exists for.

    I am leaving this issue open. One named criterion was not delivered, and this tracker was closed prematurely once already. Details at the bottom.

    Phases

    phase issue state
    G1 memory ledger FastLED/FastLED#4052 closed
    G2 CPU/codegen ledgers FastLED/FastLED#4053 closed
    G3 fixed-point minimp3 FastLED/FastLED#4054 closed
    G4 bit-exact SIMD FastLED/FastLED#4055 closed
    G5 delete libhelix FastLED/FastLED#4056 closed

    Where the licensing argument now rests

    The clean-room claim is no longer a promise, it is a property of the tree. Every fixed-point constant is generated from its ISO 11172-3 / 13818-3 formula by ci/codec_tables/generate_minimp3_fixed_tables.py and cross-checked against upstream minimp3's own CC0 float literals; Helix was never a source, not even for values that are mathematically forced. Deleting the tree is the proof — copied constants could not have been deleted.

    FASTLED.patch had gone stale during the fixed-point work and is regenerated against upstream ea99364, verified by applying it to the pristine upstream file and diffing. Nothing in CI checks that, so PROVENANCE now carries a regeneration procedure that was run verbatim rather than written from memory.

    Deviations from the plan as written

    Two of this plan's criteria were overridden by the maintainer, explicitly:

    • The one-minor-release compatibility window did not happen. Helix was deleted as soon as the tests passed: "not correct you said before that it was a one release, i'm saying instead its unit tests and perf tests passing", and "delete the helix after it's been proven that the unit tests pass... mp3 is not a high traffic codec".
    • The full Feasibility: MINIMP3_FIXED_POINT — CC0 fixed-point minimp3 mode, golden-tested vs float, to replace RPSL libhelix_mp3 #13 acceptance run did not happen — no 72-hour differential fuzz soak, no A/B listening test, no on-target ESP32-C3/RP2040/ESP32 CPU-budget measurements. Same override. What does run in CI: golden corpus gates, ISO reference vectors, fixed-vs-float PSNR/LSB gates, differential fuzzing, SIMD bit-exactness, the memory ledger and the CPU trend.

    One criterion was not delivered and is not overridden:

    Also outstanding: FastLED/FastLED#4109 (IMDCT twiddle/window vectorisation, capped near 2% and left scalar deliberately), FastLED/FastLED#4110 (the CPU trend still audits the float build; re-baselining it onto fixed point invalidates every host baseline at the moment it changes what is measured), and FastLED/FastLED#4106 (the stack watermark is not reproducible and is demoted to informational).

    Why this stays open

    The licensing objective — no RPSL/RCSL code in the tree — is met, and if that were this tracker's only content it would close today. But the plan above also commits to an ESP32-S3 PIE path that does not exist, and closing over an undelivered criterion is what went wrong here last time. Closing this is a maintainer call: either FastLED/FastLED#4108 lands, or the criterion is explicitly dropped and this closes with that recorded.

  3. zackees commented on Sep 1, 2026

    @zackees
    MemberAuthor

    The ESP32-S3 PIE criterion is settled, by measurement

    I said above that this tracker should stay open because Phase 4's "embedded flagship — ESP32-S3 PIE" item was undelivered, and that closing over an undelivered criterion is what went wrong here once already. That item is now resolved as not achievable at any acceptable precision (FastLED/FastLED#4108), so it is not deferred work.

    The instruction set does not have the primitive. The fixed-point pipeline needs a 32x32->64 widening signed multiply and a rounded narrowing shift. The ESP32-S3 PIE has neither: its multiplies are EE.VMUL.S8/EE.VMUL.S16, QACC accumulates "16 8-bit or 8 16-bit MAC results", and an independent teardown names the missing essentials as "multiply with widening" and "right shift with narrowing". FastLED's own src/platforms/esp/32/simd_xtensa.hpp had already reached the same conclusion in a different context — "operations without PIE equivalents (i32 arithmetic, float, shifts) use scalar fallback", with no ee.* instruction anywhere in the file.

    Nor is this something minimp3 introduced. Helix needed the identical primitive: MULSHIFT32 is documented as "returns top 32 bits of 64-bit result" and lowers to imul on x86, smull on ARM and mulh on RISC-V, with a full 64-bit MADD64 alongside it. Helix would not have used S3 PIE either. 32x32->64 is a property of fixed-point MP3 decoding, not of the decoder we chose.

    And the precision cost was measured, not estimated. The relevant bar is parity with Helix, not with minimp3's float build. Against the ISO limited-accuracy reference vector:

    decoder PSNR vs ISO reference
    Helix (deleted in FastLED/FastLED#4056) 102.87 dB
    minimp3-fixed (ships today) 123.24 dB
    minimp3-float (reference build) 133.79 dB
    16-bit MACs simulated in polyphase + DCT-32 44.37 dB
    ISO limited-accuracy floor 60 dB

    A 16-bit path costs ~79 dB, not the ~16 dB FastLED/FastLED#4055 estimated. That is 58 dB below Helix and 15 dB below the ISO floor -- it would fail compliance outright, not merely regress. Block floating point would beat the naive scheme but would have to recover about ten bits to reach parity, which is not an implementation-quality gap.

    Worth recording that the shipping fixed-point decoder is 20.4 dB more accurate than the Helix it replaced, on the same rig and the same vector. The licensing change was not an accuracy trade.

    Where that leaves this tracker

    Every phase is closed, and the one criterion I was holding it open for is now closed on evidence rather than dropped for convenience:

    phase issue state
    G1 memory ledger FastLED/FastLED#4052 closed
    G2 CPU/codegen ledgers FastLED/FastLED#4053 closed
    G3 fixed-point minimp3 FastLED/FastLED#4054 closed
    G4 bit-exact SIMD FastLED/FastLED#4055 closed
    G5 delete libhelix FastLED/FastLED#4056 closed
    ESP32-S3 PIE (Phase 4 flagship) FastLED/FastLED#4108 closed, not achievable
    watermark reproducibility FastLED/FastLED#4106 closed, merged

    Still open and genuinely outstanding, but none of them licensing-blocking: FastLED/FastLED#4109 (IMDCT twiddle vectorisation, measured at -2.34% instructions, in review), FastLED/FastLED#4110 (fixed-point CPU trend row, in review), FastLED/FastLED#4116 (the decoder sits at 94% of its 2 KiB stack budget; the fix is relocating inlined locals into the already-heap-allocated scratch arena).

    The two criteria the maintainer explicitly overrode -- the one-minor-release compatibility window and the full #13 acceptance run -- remain overridden, quoted in my earlier comment.

    My read is that this can close once FastLED/FastLED#4109 and FastLED/FastLED#4110 merge, with ESP32-P4 as the only thing that would legitimately reopen the PIE question, since its PIE is a different and larger instruction set. Still a maintainer call.

  4. zackees commented on Sep 2, 2026

    @zackees
    MemberAuthor

    Complete on FastLED master

    The plan in this issue — vendor minimp3, optimise to Helix parity, delete libhelix_mp3 — is done, and FastLED/FastLED#4056 is closed.

    Licence position. origin/master contains zero files under src/third_party/libhelix_mp3/. minimp3 (CC0) is the sole MP3 backend and it is unconditional: there is no FASTLED_MP3_BACKEND_HELIX symbol left, so there is not even a dormant code path. The only remaining occurrences of the string "helix" on master are comments about the retired baseline, the historical note in PROVENANCE.md, and references to SoundHelix — an unrelated test-audio website used by the audio examples.

    Not a capability regression. The parity gate this issue set was met and passed. On an ESP32-C6 the decode went from 142,647 µs to 39,385 µs — 72% — taking minimp3-fixed from 3.99× the Helix reference to 1.13×, with accuracy unchanged at 123.24 dB throughout (ISO floor 60 dB; Helix itself scores 102.87 dB). 83 ISO conformance vectors pass on the host and, bit-exactly, on riscv32 and arm.

    Three disclosures, since this is a licence issue

    1. A public fork carries Helix. The decoder is now developed at https://github.com/zackees/minimp3-fixed, and that repository includes helix/ as the benchmark reference it was measured against. It is RPSL/RCSL, not CC0 like the rest of that repo; RPSL.txt and RCSL.txt travel with the code and helix/README.md states plainly that the directory is not part of the library and must not be copied into a product. This was a deliberate call — a number quoted against a decoder nobody can run is not a measurement — but it is a decision worth revisiting now that parity is reached and the reference has served its purpose.

    2. Deleting branches does not remove Helix from FastLED's git history. Every commit before #4056 still contains the tree. Removing it from history would require a rewrite, which has not been done and is not proposed here. The claim that holds is precise: Helix is gone from what FastLED ships and from every branch tip that anyone is likely to build.

    3. About 15 recent branches still carry Helix at their tips, simply because they were cut from master before the removal landed and have not been rebased. They will drop it on their next rebase or merge. The three MP3-specific branches (feat/helix-benchmark-reference, perf/minimp3-fixed-point, feat/mp3-autoresearch) have been deleted; the rest belong to unrelated work.

    Closing. Reopen if the fork's helix/ directory should be removed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions