Skip to content

Meta: #2994 timing regression — retract the refresh-throttle root cause, find the real show() duration regression #3765

Closed

Description

@zackees

Meta-tracker for the #2420 / #2994 timing regression. Opening this because the root cause I published on #2994 was wrong and the issue was auto-closed on it. This issue records the retraction, what is actually established, and the work left.

Correction: the refresh throttle is not the cause

I claimed on #2994 that the drift came from FreeRTOS tick quantization inside CFastLED::show()'s refresh-rate throttle, and #3764 was merged on that basis (auto-closing #2994).

The throttle never executes in the reporter's sketch.

show() is gated by ms_fast_led at 5 ms. Subtracting the ~1050 us WS2812 transmit for 35 LEDs, the throttle sees ~3950 us elapsed against mNMinMicros = 1250 us at setMaxRefreshRate(800):

show() called every                  5000 us
WS2812 transmit, 35 LEDs             1050 us
elapsed seen by throttle             3950 us
mNMinMicros @ setMaxRefreshRate(800) 1250 us
throttle engages?                    NO  (3950 >= 1250, loop condition false on first check)

So the code path #3764 changed is not reached by this sketch and cannot explain the reported drift.

How the wrong conclusion survived review: the supporting arithmetic (predicted 25-299 ms vs reported 63-300 ms) was produced by choosing a per-frame jitter fraction freely across an order of magnitude. Three arbitrary multipliers will bracket almost any target. That was curve-fitting presented as confirmation, and the one falsifying check — does the throttle condition ever evaluate true here? — was never run despite the sketch being available throughout.

What the evidence actually points to

Reported drift is 68-257 ms over 254 fade steps = 268-1012 us per step. A single WS2812 show() for 35 LEDs is ~1050 us.

The per-step excess is the same order as one show() call, which points at show() duration (and the resulting loop-poll latency around the millisDelay deadline) rather than any throttle quantization. The reporter's loop polls justFinished() once per iteration, so a longer show() widens the window between a 5 ms deadline passing and the poll observing it, and that excess accumulates across 254 steps.

The open question is therefore: why did FastLED.show() get slower between 3.10.3 and master on ESP32-S3? Candidates, unranked and unmeasured:

  • the RMT5 / channels driver rewrite (per-frame setup cost, waitForCondition tiers)
  • transposition / encoding cost per frame
  • EngineEvents onBeginFrame / onEndFrame listener work
  • per-frame allocation or logging added since 3.10.3

Established and worth keeping

Not everything from the investigation was wrong:

  • fl::task::run(<non-zero>, SYSTEM) discards its microseconds argument and hardcodes pumpCoroutines(1000) (executor.cpp.hpp:138). Every caller asking for a shorter yield silently gets 1000 us, then tick-rounded. Real bug, independent of [Bug] Compounded timing inaccuracy on master compared to 3.10.3 (Follow-up to #2420) #2994.
  • ICoroutineRuntime::needsDeepYield() is dead code — implemented at coroutine_esp32.impl.hpp:88, called from nowhere, duplicating NetworkDetector with weaker semantics (no BT, no Ethernet).
  • fix(core): adaptive yield in show()'s refresh throttle (#3762, fixes #2994) #3764's own threshold is wrong: it guards the deep yield with remaining > spinBudget (250 us) when a deep yield costs up to one tick (1000 us). Simulated over 200k frames at 800 Hz / 1 kHz tick, that leaves ~281 us mean overshoot where a tick-period threshold leaves zero. Minor now that we know the path is rarely hit, but still incorrect.
  • AutoResearchTimingDrift.h faithfully replays the reporter's sketch and exposes timingDriftTest over JSON-RPC — but it has no host driver. Nothing in ci/ references it and there is no --timing-drift flag, so it has never been run.

Work items

Blocker

On-device validation is currently blocked by fbuild on this bench — orphaned mkdir install-locks, a stale daemon endpoint surviving daemon stop, and an esptool provisioning failure that kills the daemon. Filed as FastLED/fbuild#1213. Every failure mode was silent at the client: bash compile exits 0 while printing ERROR! There were 1 failures, and fbuild deploy exits 1 printing only a version notice.

Related

Activity

  1. zackees commented on Jul 29, 2026

    @zackees
    MemberAuthor

    Status: 6 of 8 items done, 2 blocked on hardware

    Three PRs merged since this issue opened.

    Done

    Blocked

    • Measure show() duration, 3.10.3 vs master — the decisive comparison.
    • Bisect once a delta is confirmed.

    Both need a board. The ESP32-C6 dropped off the USB bus during deploy attempts (VID_303A no longer enumerates) and needs a physical replug; FastLED/fbuild#1213 tracks the fbuild failures that preceded it.

    What the search has narrowed to

    Two independent results now bracket the cause:

    1. tests/profile/fastled_show.cpp (fix(profile): repair bash profile, add a show() CPU-cost benchmark (#3765) #3767) measures the CPU-side per-frame path at ~2 us/frame for 35 LEDs — three orders of magnitude below [Bug] Compounded timing inaccuracy on master compared to 3.10.3 (Follow-up to #2420) #2994's 268-1012 us of per-step excess. So the regression is not in EngineEvents, the three-pass controller walk, dithering/scaling, or the feat(channels): compile-time Bus binding via templated ChannelConfig (eliminates Channel API binary bloat) #2428 channels dispatch.

    2. That benchmark cannot see encoding/bit-transposition, DMA, or driver wait loops, because the host driver is a stub. Those are now the prime suspects precisely because they are what it cannot measure.

    test_timing_drift.py closes the loop: the firmware already returns show_min_us/show_max_us/show_total_us, which nothing consumed. One run on each version answers it — if show() sits well above the ~1050 us wire floor for a 35-LED WS2812 frame, that excess is the regression.

    Two process findings worth keeping

    • The reproducer had no host driver. AutoResearchTimingDrift.h faithfully replayed the sketch and exposed timingDriftTest, but nothing in ci/ referenced it, so it had never been run. That is plausibly why this went a year with a wrong root cause — including mine: one run would have refuted my throttle hypothesis immediately. Hypotheses were being tested by argument because the measurement path did not exist.
    • bash profile was broken for every target (fixed in fix(profile): repair bash profile, add a show() CPU-cost benchmark (#3765) #3767) — profile_runner.py passed --build, which argparse abbreviation-matched into --build-mode, eating its value.

    Both are the same shape: measurement tooling that existed on paper but could not be invoked.

  2. zackees commented on Jul 29, 2026

    @zackees
    MemberAuthor

    Closing. This tracker was opened to do three things, and all three are done:

    1. Retract the wrong root cause and get [Bug] Compounded timing inaccuracy on master compared to 3.10.3 (Follow-up to #2420) #2994 reopened so its reporter is not left believing it is fixed. Done — retraction posted with the falsifying arithmetic.
    2. Fix what was genuinely broken that the investigation uncovered. Done across three merged PRs.
    3. Narrow the search and build the tooling to settle the real cause. Done.

    Merged

    PR What
    #3766 task::run() clamps its SYSTEM yield to the caller's budget; deleted dead needsDeepYield() + its isWiFiActive() helper and orphaned esp_wifi include
    #3767 Repaired bash profile — broken for every target; added tests/profile/fastled_show.cpp
    #3768 ci/autoresearch/test_timing_drift.py — the host driver the #2994 reproducer never had

    Resolved by analysis

    #3764's threshold — answered on #3762. It is a tradeoff, not a defect: the 250 us default costs ~140 ms/sequence of jitter at 0.6% CPU, while the 1000 us tick threshold gives exact timing at 10% CPU that starves lwIP — the exact thing #2254 fixed. setWaitSpinBudgetUs() already exposes both ends, so this is a documented-default question. Recommendation recorded: keep the current default.

    Handed off, not dropped

    The two remaining items — measure show() duration on 3.10.3 vs master, then bisect — are the live investigation, and they belong on #2994, which is reopened. Full state, the decision rule, and the exact command are posted there, so this tracker is now redundant rather than incomplete.

    They need a board. The ESP32-C6 here dropped off the USB bus (VID_303A stopped enumerating) and needs a physical replug; the fbuild failures that preceded it are FastLED/fbuild#1213.

    The finding most worth keeping

    Two pieces of measurement tooling existed on paper but could not be invoked: the timingDriftTest reproducer had no host driver, and bash profile was broken for every target. That is plausibly why #2994 survived a year with a wrong root cause — mine included. One run of that reproducer would have refuted my throttle hypothesis immediately; instead it got settled by argument, and the arithmetic I offered as confirmation was curve-fitting.

    Both tools now work. The next hypothesis gets measured instead of argued.

  3. moved this from Triage to Done in FastLED Trackeron Jul 29, 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