Skip to content

chore(mp3): leftovers from the fixed-vs-Helix work -- ledger path filter, huffman regression, upstreaming #4155

Open

Description

@zackees

Follow-up to #4138 and #4139, which are closed: the fixed-point decoder went from 3.99x Helix on an ESP32-C6 to 1.13x (#4140, #4150), and the shipping backend is now gated on a Callgrind, codegen and exact-operation baseline in codec_cpu_trend.json (#4148). Three items from those issues were never done and are collected here so they do not get lost.

1. codec_cpu_ledger.md does not exist but the workflow path-filters on it

.github/workflows/mp3_cpu_audit.yml lists codec_cpu_ledger.md in both its push and pull_request path filters (lines 19 and 34). The file has never existed; the real store is codec_cpu_trend.json. Either drop the two entries or create the file. Dropping is the simpler fix.

2. The fixed build's huffman stage is unexplained

Per-frame host medians recorded in agents/docs/mp3-decoder-performance.md:

stage float fixed
huffman 7,373 ns 12,134 ns

Huffman is integer work in both builds, so the fixed-point DSP does not explain a 1.6x difference there. Worth a Callgrind diff of L3_huffman between the two builds. It may be scratch-clearing or inlining differences rather than the decoder itself; ecb3d0588d already trimmed the scratch clear, so re-measure before assuming the number in the doc is current.

3. Nothing has gone upstream to lieff/minimp3

The fixed-point port is a FastLED fork. The findings that are of general interest and not FastLED-specific:

  • mp3d_sat64 on every polyphase intermediate is redundant on conformant input (zero clamps across 82.5M calls on real music; all 4,609 clamps in the ISO suite come from l3-nonstandard-big-iscf).
  • mp3d_mulshift_k for constant coefficients on targets without a single-register 64-bit product.
  • The int64-heavy arithmetic is roughly free on x86-64 and 4x on a 32-bit RISC-V core, so host ratios understate the embedded gap.

Open an issue or PR against https://github.com/lieff/minimp3 pointing at the relevant commits.

Not in scope

🤖 Generated with Claude Code

https://claude.ai/code/session_01XQyTuAVs4tK9pDcxAZVqVe

Activity

  1. zackees commented on Sep 7, 2026

    @zackees
    MemberAuthor

    The first item here — the dead codec_cpu_ledger.md path filter — is done. It landed in #4176, which carried the identical two-line deletion alongside its own changes, so #4175 was closed as already applied (rebasing it onto master drops the commit with "patch contents already upstream").

    The other two items in this issue are untouched.

    One thing surfaced while chasing #4175's red CI that is worth recording here, since it lives in the same workflow. The MP3 SIMD-vs-scalar gate is runner-dependent: it measures 1.080x on some GitHub runners and 0.904–0.945x on others, a 19% spread across a fleet that is not one machine. It is not noise and it is not a straightforward regression — the kernel is genuinely faster on some GHA silicon and genuinely slower on other. It takes master red at random.

    That is tracked separately in #4183, and #4192 has landed the diagnostics (the ratio, whether it was enforced, and the runner CPU are now recorded on passing runs too). Mentioning it here only because anyone picking up the remaining mp3_cpu_audit.yml work will run into it.

  2. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Item 2 is done as well — closed in #4254, and the answer was "no"

    Following the triage comment above, which left items 2 and 3 open. Item 2 is no longer one of them; it was resolved on 2026-09-09 in #4254 (a75d510573) and recorded in agents/docs/mp3-decoder-performance.md, but nothing said so here.

    This issue asked for a Callgrind diff of L3_huffman. That diff was not run, deliberately, because the two premises behind it both failed the re-measurement this issue itself asked for:

    The number was stale. The 12,134 ns in the table came from before ecb3d0588d trimmed the scratch clear. Re-measured it is 9,127 ns, a 1.24x ratio rather than 1.65x. What makes that believable rather than machine drift is the float side: it reproduces its old 7,373 to within 0.5% on the same host, so only the fixed side moved.

    And the premise was wrong. The issue's reasoning was "huffman is integer work in both builds, so the fixed-point DSP does not explain the difference". It is not integer-only work — audit.py declares dequant fused into huffman for both minimp3 backends, which is why the dequant row reads 0.0 ns. minimp3 dequantises inline as it decodes, and the two builds differ there by construction:

    // fixed
    #define MP3D_HUFF_TAB(idx)  mp3d_dequant(one_m, one_e, g_pow43_mant[idx], g_pow43_exp[idx])
    // float
    #define MP3D_HUFF_TAB(idx)  (g_pow43[idx]*one)

    A mantissa/exponent dequant call against one float multiply per coefficient. So the residual 1.24x is the arithmetic doing exactly what it was changed to do, not an anomaly. The Callgrind diff would have shown that and nothing else.

    Where the time actually goes, from the same table: IMDCT 3.05x, stereo 2.77x, antialias 2.58x — all genuine DSP stages, all larger multiples than huffman ever was.

    What is left

    Only item 3, upstreaming to lieff/minimp3. I have not done it: it means opening an issue or PR on a third-party project under your GitHub identity, which is not something I will do without you saying so explicitly. The three findings are written up and ready if you want them filed — say the word and I will draft the upstream issue text here for you to post, or post it myself if you would rather.

  3. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Two of the three are already done; the third is the only one left, and it is not mine to send

    Checked each item against the tree rather than against the issue text.

    1. Ledger path filter — done, incidentally

    mp3_cpu_audit.yml no longer path-filters on codec_cpu_ledger.md. Both push and pull_request now list codec_cpu_trend.json, the store that actually exists:

    $ grep -n codec_cpu .github/workflows/mp3_cpu_audit.yml
    19:      - 'codec_cpu_trend.json'
    33:      - 'codec_cpu_trend.json'
    

    It went out in #4176 (git log -S "codec_cpu_ledger.md" shows it added by #4064 and removed there) — not as part of this issue, which is why it was never marked. Every path the workflow filters on now resolves; I checked them individually, so there is no second instance of the same bug hiding in the list.

    2. Huffman — done, and the premise was wrong

    agents/docs/mp3-decoder-performance.md carries a section named for this issue ("The huffman stage is not the lead it looked like"). Both halves of the item failed:

    • The 12,134 ns figure was stale. Re-measured: 9,127, a 1.24x ratio rather than 1.65x. What makes that believable rather than machine drift is that the float side reproduces its old 7,373 to within 0.5% on the same host. ecb3d0588d trimmed the scratch clear between the measurements — exactly the "re-measure before assuming the number is current" this issue warned about, and it was the right warning.
    • "Huffman is integer work in both builds" was false. audit.py fuses dequant into huffman for both minimp3 backends, because minimp3 dequantises inline as it decodes. So the stage differs by construction: one float multiply per coefficient (g_pow43[idx]*one) against a mantissa/exponent mp3d_dequant call. A residual 1.24x is the arithmetic doing what it was changed to do.

    The doc states plainly that the Callgrind diff this issue asked for "would have shown this and nothing else, which is why it was not run" — a defensible reason not to run a measurement, since the attribution was already decided by audit.py's own stage fusion. The real weight is IMDCT 3.05x, stereo 2.77x, antialias 2.58x.

    3. Upstreaming to lieff/minimp3 — outstanding, and deliberately not done here

    This is the only item left. I have not opened it, because filing an issue or PR on a third-party repository is an outward-facing action under someone else's name and a maintainer's call, not a housekeeping step I should take on my own. The three findings are ready to send as written:

    • mp3d_sat64 on every polyphase intermediate is redundant on conformant input — zero clamps across 82.5M calls on real music; all 4,609 in the ISO suite come from l3-nonstandard-big-iscf.
    • mp3d_mulshift_k for constant coefficients on targets without a single-register 64-bit product.
    • Host ratios understate the embedded gap: the int64-heavy arithmetic is ~free on x86-64 and 4x on 32-bit RISC-V.

    Say the word and I will draft it against https://github.com/lieff/minimp3 with links to the relevant commits.

    So this issue reduces to item 3. Items 1 and 2 can be struck.

  4. zackees commented on Sep 12, 2026

    @zackees
    MemberAuthor

    Item 1 is done — and most of it turned out to be already done.

    The workflow no longer path-filters on codec_cpu_ledger.md; both its push and pull_request filters list codec_cpu_trend.json alone, and the name appears nowhere under .github/. What was left was agents/docs/mp3-decoder-performance.md, which still described the filter as present:

    There is also no codec_cpu_ledger.md, despite .github/workflows/mp3_cpu_audit.yml path-filtering on it.

    Corrected in #4389. The warning that paragraph exists for — do not conclude "Helix was never profiled" from grep -c on a missing file — is kept, since that is the mistake the whole note is guarding against.

    Item 2 may be reachable locally after all

    Worth recording before anyone else is put off. My working notes said Callgrind is unusable on this host, which is true of ci/codec_cpu/audit.py --check: it passes --instr-atstart=no, and NixOS valgrind 3.26.0 then writes totals: 0 — one value for five events — so parse_callgrind dies with zip() argument 2 is shorter.

    But ci/codec_cpu/callgrind.py passes --instr-atstart=yes (line 311), which is the case that does not trip it. So the L3_huffman float-vs-fixed diff this item asks for is probably runnable here, and "Callgrind does not work on this machine" is too broad a conclusion to carry forward.

    Also still true, per the issue: ecb3d0588d trimmed the scratch clear after those medians were recorded, so the 7,373 / 12,134 ns figures want re-measuring before anything is inferred from the 1.6x.

    Item 3 unchanged

    Opening an issue or PR against lieff/minimp3 is outward-facing. That needs a maintainer's go-ahead rather than an agent's, so it stays open.

  5. zackees commented on Sep 12, 2026

    @zackees
    MemberAuthor

    Item 2 is resolved, and I can now confirm empirically the one claim its resolution makes without evidence.

    agents/docs/mp3-decoder-performance.md already carries the answer under "The huffman stage is not the lead it looked like": the 12,134 ns figure was stale (re-measured at 9,127, a 1.24x ratio), and the premise was wrong because audit.py fuses dequant into huffman for both minimp3 backends — minimp3 dequantises inline as it decodes, so the row was never integer-only work.

    That section ends with:

    The Callgrind diff of L3_huffman that #4155 asked for would have shown this and nothing else, which is why it was not run.

    I ran it, and that is right. L3_huffman has no separate symbol to diff:

    top functions (tree, minimp3-fixed):       top functions (tree, minimp3-float):
      41.3%  98,618,636  mp3d_synth               49.5%  76,996,030  mp3d_synth_granule
      18.8%  44,949,983  mp3dec_decode_frame_r    17.0%  26,537,313  mp3dec_decode_frame_r
      13.7%  32,762,014  mp3d_synth_granule       14.9%  23,184,320  L3_imdct36
      11.9%  28,475,840  L3_imdct36                7.1%  11,125,760  L3_dct3_9
    

    callgrind_annotate at a 99.99% threshold lists every minimp3 symbol in the binary, and L3_huffman is not among them — it is inlined into mp3dec_decode_frame_r. The only "huffman" string anywhere in the profile is the stage-name array itself.

    So the diff would have returned nothing, exactly as claimed. What it does show is mp3dec_decode_frame_r at 44.9M against 26.5M instructions, a ratio of 1.69 — close to the 1.65x the old stage timer reported, which is consistent with that timer bracketing a region Callgrind sees as one inlined function containing huffman, dequant, stereo and reorder together.

    Worth correcting in my previous comment

    I said above that Callgrind was "probably runnable here" because callgrind.py passes --instr-atstart=yes. That is confirmed — it ran clean, both decoders, no parser failure. The totals: 0 problem is specific to audit.py --check and its --instr-atstart=no.

    Remaining

    Only item 3, opening an issue or PR against lieff/minimp3. That is outward-facing and wants a maintainer's decision rather than an agent's, so I am leaving this issue open on that alone.

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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions