Skip to content

MP3 SIMD kernel may be genuinely slower than scalar on GHA x86 runners (blocks #4175) #4183

Closed

Description

@zackees

FL_CHECK_GE(ratio, 0.95) in the minimp3 fixed-point SIMD is not slower than scalar test case (tests/fl/codec/mp3_fixed_point.hpp) fails intermittently on GitHub's ubuntu-24.04 runners. It has taken down the MP3 CPU audit workflow on master twice and is currently the only thing blocking #4175, a two-line path-filter cleanup that cannot affect codec behaviour.

Observed failures

Every recent failure of that workflow is this assertion:

run branch reported ratio
2026-09-07 chore/4155-drop-dead-ledger-path-filter (#4175) 0.945
2026-09-06 master 0.904
2026-09-04 master 0.924

The 9 successful runs in the same window all executed the test (Running: fl_codec appears in each log) and passed silently — the harness only echoes test stdout when a test fails, so their ratios were not recorded.

The measurement cannot resolve the effect it gates on

The in-source comment says "x86 measures ~1.10x". It does not. Running the compiled release test directly on a quiet AMD Ryzen 7 3700X (ssse3 + avx2), 12 consecutive runs:

1.022 1.014 1.009 1.014 1.010 1.011 1.030 1.026 1.021 1.008 1.026 1.058

The true speedup on this corpus is about 1.02x, not 1.10x. That leaves only ~7% of headroom above the 0.95 threshold, and the estimator's run-to-run spread is the same order as the effect.

Under CPU contention (20 spinners on 16 cores, simulating a shared runner) the same 12-run sweep spreads to 1.007 – 1.246. So contention alone moves the number by more than 20%.

A gate whose noise band is roughly 10x the effect it measures (2%) cannot distinguish "the SIMD kernel regressed" from "the runner was busy." That is the defect — the threshold is not obviously wrong, the estimator is.

An obvious fix does not work

The natural repair is a robust estimator: take the minimum per-rep time for each variant instead of the sum, since contention only ever adds time. I implemented and measured it. It is not better:

condition sum-of-reps min-of-reps
idle, 12 runs 1.008 – 1.058 0.994 – 1.021
under load, 12 runs 1.007 – 1.246 0.939 – 1.119

Under load the min estimator dipped to 0.939 — below the threshold — while the sum estimator never went under 1.007. Recording this so nobody re-derives it: the change was reverted and is not proposed.

What is worth considering

  1. Drop the assertion, keep the print. The in-source comment already says the gate that counts is ci/codec_cpu/audit.py, which builds optimised and compares against recorded baselines. This unit-test check is redundant with it, and is the only one that is flaky.
  2. Make the measurement resolve 2% — many more reps, finer-grained interleaving, or pinning. Speculative; nobody has shown it works.
  3. Confirm the direction on GHA hardware. All three failures came from GHA runners; my host never went below 1.007 even under heavy load. If the SIMD path is genuinely slower on some runner microarchitecture, that is a real finding and the gate is right — but it would need a run that reports the ratio from a passing GHA run to tell apart, which the harness currently suppresses.

Whatever is chosen, the in-source "~1.10x" claim should be corrected — it is off by 5x on the margin that matters.

Related: #4055 (the perf bar this gate enforces), #4175 (blocked by it).

Activity

  1. zackees commented on Sep 7, 2026

    @zackees
    MemberAuthor

    Correcting my framing above — the evidence now points the other way.

    I re-ran the failed job on #4175 to see whether it would go green. It failed again at 0.920x. That makes four visible GHA measurements:

    run scalar (8 reps) ratio
    #4175 first 113 407 µs 0.945
    #4175 rerun 109 703 µs 0.920
    master 09-06 74 199 µs 0.904
    master 09-04 95 892 µs 0.924

    Four out of four below the threshold, clustered in a 0.04 band. That is not what noise around a true value of 1.02 looks like — I over-read the 9 passing runs as evidence of a distribution straddling 0.95.

    The decisive detail is the third row. That run had a scalar time of 74 199 µs — 45% faster than my Ryzen 7 3700X managed at 107 917 µs, so it was a fast runner that was not fighting for CPU. It produced the worst ratio of the four. A contention artifact cannot look like that; contention makes runs slower, not faster-and-more-lopsided.

    So the likely reading is the opposite of my first one: the SIMD kernel is genuinely ~8% slower than scalar on GitHub's x86 runners, and the gate is correctly reporting a real property rather than flaking. My host disagrees (1.00–1.06, never below 1.0) — an AMD Zen 2 part, against whatever Intel/AMD server silicon GHA schedules. A marginal kernel flipping sign across microarchitectures is entirely ordinary.

    What I still cannot tell from the logs, and what would settle it: the 9 passing runs may not have exercised the gate at all. The test returns early when dspUsesSimd() is false, and the harness suppresses stdout for passing tests — so a runner without the required ISA passes vacuously and looks identical to one that measured 1.05. If that is what the passing runs are, then every runner that actually ran the comparison found SIMD slower, and there is no flakiness here whatsoever.

    Cheapest way to find out: make the harness echo that test's output on success too, or have the workflow run it with the verbose flag, so a passing run records either a ratio or the "no integer SIMD on this target" line.

    What this changes:

    Still true and still worth fixing regardless: the in-source "x86 measures ~1.10x" comment is not what any of these five machines measure.

  2. changed the title [-]MP3 SIMD perf gate is flakier than the effect it measures (blocks #4175)[/-] [+]MP3 SIMD kernel may be genuinely slower than scalar on GHA x86 runners (blocks #4175)[/+] on Sep 7, 2026
  3. zackees commented on Sep 7, 2026

    @zackees
    MemberAuthor

    Opened #4192, which should settle the open question here.

    The harness echoes a test's stdout only when it fails, so a passing run of this gate records nothing — and the gate can also pass vacuously, because the comparison returns early on a target with no integer SIMD. A green result is therefore indistinguishable from a skipped measurement, which is exactly why the nine passing runs can't be used as evidence either way.

    #4192 adds --verbose to that workflow step so the ratio is printed regardless. The next audit run then tells us directly whether the passing runs measured a healthy ratio or never ran the comparison at all — and that decides between "the SIMD kernel is genuinely slower on GHA silicon" and "the gate is noisy".

  4. zackees commented on Sep 7, 2026

    @zackees
    MemberAuthor

    Answered. The first run of #4192, which adds --verbose to this step, reports:

    [simd-perf] scalar=134366 us  simd=124366 us  speedup=1.080x over 8 reps
    

    on a passing run, with no no integer SIMD on this target line. So the gate really runs on the passing runners and really measures a healthy ratio — the passing runs were never vacuous.

    Which means neither of my earlier readings was right

    I first called this a flaky gate. I then corrected that, on the strength of four failures clustering at 0.904–0.945 with the fastest scalar time producing the worst ratio, and said the kernel was probably genuinely slower on GHA silicon.

    Both were too simple. The measurements now span 0.904 to 1.080 — a 19% spread — and GitHub's runner fleet is not one machine. The honest reading is that the SIMD kernel is genuinely faster on some GitHub runners and genuinely slower on others. Both sets of numbers are correct measurements of different hardware.

    That also explains the shape of the record: about ten runs at or above 0.95 and four below it, which is bimodal rather than a noisy distribution around a single value.

    What that implies for the gate

    A wall-clock threshold that holds on one runner class and fails on another cannot stay a hard gate — it will keep taking the default branch red at random. Options, roughly in order of cost:

    1. Make it informational. The in-source comment already says the gate that counts is ci/codec_cpu/audit.py, which builds optimised and compares against recorded baselines. This one is the only flaky half.
    2. Lower the threshold below the slow population (~0.88), keeping it as a guard against a real regression rather than a claim about parity. Cheap, and it still catches the SSE2 emulation case it was written for, which came in at 0.95.
    3. Pin the job to a runner class so it measures one thing.

    #4192 also now records lscpu alongside the ratio, so the next few runs will name the two populations instead of leaving this to inference.

    Separately, the in-source comment claiming "x86 measures ~1.10x" is closer than I gave it credit for — it matches the fast population — but it is not what the slow one measures, and it reads as though there were only one answer.

  5. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Two new data points, and a fix in #4263

    This just failed #4256 — a PR that touches only ci/tools/ and cannot affect codec behaviour, which is the same shape as #4175 being blocked. So it is still taking unrelated work red.

    The slow population is not only GHA x86

    [simd-perf] scalar=330129 us  simd=357947 us  speedup=0.922x over 8 reps (integer SIMD: yes, ratio enforced)
    

    That run was on a macOS ARM runner — /Users/runner/work/..., /opt/homebrew/bin/git. Your analysis inferred the slow population was GHA x86; it includes Apple Silicon too, which if anything strengthens the bimodal reading rather than complicating it.

    And a host measurement between the two populations

    An optimised local build (--build-mode release), across runs:

    speedup=1.005x
    speedup=1.002x
    speedup=0.993x
    

    That sits between the fast (1.080) and slow (0.904–0.945) populations, and straddles the margin 0.95 relied on all by itself on one quiet machine. Consistent with your Ryzen at ~1.02.

    What #4263 does

    Option 1 from your list, with a floor kept rather than dropping the assertion: ratio >= 0.5. A vector path twice as slow as the scalar one it replaces is a defect on any machine, and 0.5 is far outside anything the fleet has produced.

    I did not take option 2 (threshold ~0.88): the slow population reaches 0.904, so 0.88 leaves about 2% of margin against a distribution that has already moved 19%. That is the same bet that just failed, at a lower number.

    The loss is real and I have said so in the PR rather than implying parity is still guarded: a subtle regression will not be caught here. Nothing measured on a heterogeneous fleet can catch one, which is the finding, and ci/codec_cpu/audit.py is where that belongs — it builds optimised and compares against recorded baselines instead of against the scalar path on whatever silicon it drew. The ratio still prints on every run.

    The in-source "~1.10x" comment is corrected to name both populations.

    One verification note worth recording

    The assertion is __OPTIMIZE__-gated, so quick mode compiles it out entirely. My first mutation test ran against a stale quick-mode binary and reported the mutation surviving — it had simply never been compiled. Anyone verifying changes to this gate needs --build-mode release, or they are testing nothing.

  6. moved this from Triage to Done in FastLED Trackeron Sep 10, 2026
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