Repository navigation
Description
Summary
CFastLED::show()'s refresh-rate throttle is the last call site still taking an unconditional deep yield. Every other site that had this problem was already fixed — by runtime NetworkDetector gating (#2817) and by skipping the vTaskDelay(1) floor (#2493 follow-up, 9d71de01d0). show() was missed, and that is the root cause of the timing regression in #2994.
This issue proposes finishing the job, and asks a second question: whether the yield is needed at all anymore now that transposition is fast.
Current state
src/FastLED.cpp.hpp:238 (introduced in 5c8f7a1e7f, "try and fix wifi slowdown", refs #2193):
while (mNMinMicros && ((fl::micros() - lastshow) < mNMinMicros)) {
#if SKETCH_HAS_LARGE_MEMORY
fl::task::run(250, fl::task::ExecFlags::SYSTEM);
#endif
}Chain of costs:
executor.cpp.hpp:135-141— becausemicroseconds > 0, this callspumpCoroutines(1000). The caller's 250 is discarded; 1000 is hardcoded.coroutine_esp32.impl.hpp:82-85—if (ticks == 0) { ticks = 1; }thenvTaskDelay(ticks).- Net: ≥1 FreeRTOS tick per loop iteration — 1 ms at
CONFIG_FREERTOS_HZ=1000, 10 ms at the 100 Hz default.
At setMaxRefreshRate(800) the throttle target is 1250 µs, so every show() overshoots to a tick boundary. Measured effect in #2994: 499 shows/sequence × 0.05–0.6 ms = 25–299 ms drift, against 63–300 ms reported. 3.10.3's plain busy-wait was microsecond-accurate, which is why it reported a rock-steady 2495 ms.
This is the same defect 9d71de01d0 already described for waitForCondition, quoting its own commit message:
waitForConditioncalltask::run(250, SYSTEM)once per iteration to keep WiFi/lwIP alive while polling. On ESP32-P4 atCONFIG_FREERTOS_HZ=1000this floor-rounds tovTaskDelay(1)= 1 ms minimum per iteration.
Proposal 1 — gate the show() throttle on NetworkDetector
fl::NetworkDetector already exposes exactly what is needed, and the channel wait sites already use it (driver.cpp.hpp:51, manager.cpp.hpp:477):
| API | Semantics |
|---|---|
weak symbol == nullptr |
component not linked — free, covers most LED-only sketches |
isWiFiActive() |
esp_wifi_get_mode() != WIFI_MODE_NULL (initialized) |
isWiFiConnected() |
esp_wifi_sta_get_ap_info() == ESP_OK (associated) |
isBluetoothActive() |
esp_bt_controller_get_status() == ENABLED (enabled, not merely initialized) |
isAnyNetworkActive() / isAnyNetworkConnected() |
aggregates |
Recommend isAnyNetworkActive(), matching the existing channel sites — not isAnyNetworkConnected(). Scanning and association are precisely when the WiFi stack most needs CPU; gating on Connected would skip the yield during exactly that window, reinventing the pre-connection gap the executor comment warns about.
Sub-tick handling should follow 9d71de01d0: only take the deep yield when at least a full tick remains; spin the remainder. Above ~1000 Hz refresh the entire wait is sub-tick, so today it is pure quantization noise.
Proposal 2 — dead code to resolve either way
ICoroutineRuntime::needsDeepYield() (coroutine_esp32.impl.hpp:88, overriding coroutine_runtime.h:47) implements cached WiFi detection and is called from nowhere. It duplicates NetworkDetector with weaker semantics (WIFI_MODE_NULL only, no BT, no Ethernet). Either wire it to NetworkDetector or delete it.
Separately, executor.cpp.hpp:138 ignoring its microseconds argument is a bug independent of all of the above — every caller asking for a shorter yield silently gets 1000 µs, then tick-rounded.
Open question — is the yield still needed at all?
The yield was added for #2193/#2254, when the starvation cause was long blocking transposition inside the driver. That has since been substantially optimized. If transposition no longer blocks long enough to starve lwIP, the correct fix may be to drop the yield from show() entirely rather than gate it — show()'s throttle is a timing wait, not a DMA wait, and the caller explicitly asked to be blocked until the refresh interval elapses.
This should be settled by measurement, not argument.
Proposed experiment (ESP32-C6 on the bench)
Three build variants, two network conditions:
| variant | show() throttle |
|---|---|
| A | master (unconditional deep yield) |
| B | NetworkDetector::isAnyNetworkActive()-gated + sub-tick spin |
| C | no yield (3.10.3 behavior) |
Conditions: (1) WiFi off, (2) WiFi connected with sustained traffic (iperf or websocket echo).
Metrics:
- per-
show()latency distribution (min/mean/p99) atsetMaxRefreshRate(800) - sequence time vs the 2495 ms reference from [Bug] Compounded timing inaccuracy on master compared to 3.10.3 (Follow-up to #2420) #2994
- network throughput / dropped frames under condition 2
Decision rule:
- If C shows no throughput regression under condition 2 → drop the yield from
show(); simplest and fastest. - If C regresses but B does not → ship B.
- If B also regresses → the yield is load-bearing; revisit
mNMinMicrossemantics instead.
Acceptance
- [Bug] Compounded timing inaccuracy on master compared to 3.10.3 (Follow-up to #2420) #2994's reporter sees a steady 2495 ms sequence on ESP32-S3
- no throughput regression in the ESP32-S3: I2S driver starves websockets, SPI output incorrect, Audio driver FPS impact #2254 websocket scenario
needsDeepYield()either wired up or removedexecutor.cpp.hpphonors itsmicrosecondsargument
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Jul 29, 2026
Quantified the threshold question from #3765, and the answer is a tradeoff rather than a bug — so recording the numbers here instead of picking a default unilaterally.
The observation
#3764's throttle guards the deep yield with
remaining > spinBudget, where the defaultspinBudgetis 250 us. But a deep yield costs up to one full FreeRTOS tick (1000 us atCONFIG_FREERTOS_HZ=1000). So whenremaininglands in (250, 1000), the throttle takes a yield that can overshoot its own deadline.Simulation
200k frames,
setMaxRefreshRate(800)(mNMinMicros= 1250 us), 1 kHz tick, uniform tick phase:Why this is a tradeoff, not a defect
The tick threshold gives exact timing — but the spin is
task::run(0)=taskYIELD(), which per #2254's own analysis does not yield to lower-priority tasks. lwIP sits below the LED task. So the precise variant burns ~10% CPU in exactly the way that starves WiFi, which is the thing #2254 fixed.On a tick-quantized RTOS you cannot have both microsecond-accurate throttling and full lower-priority yielding. The current 250 us default buys WiFi throughput at the cost of ~140 ms/sequence of jitter for radio-up users; 1000 us inverts that.
The knob already exists —
FastLED.setWaitSpinBudgetUs(1000)gets exact timing today for anyone who wants it, andsetWaitSpinBudgetUs(0)disables spinning entirely for maximum throughput. So this is a documented-default question, not missing capability.Recommendation
Leave the default at 250 us. It preserves the #2254 fix, which is a correctness property, over timing precision, which is tunable. Worth a doc note on
setMaxRefreshRatethat with a radio active the throttle is tick-quantized andsetWaitSpinBudgetUstrades CPU for precision.Caveat worth stating
This matters much less than I implied when I opened #3765. The throttle provably does not engage in #2994's sketch (
show()is gated at 5 ms, far above the 1250 us threshold), so none of the above explains that report. The real #2994 investigation is tracked in #3765 and now points atshow()duration — encoding, DMA, or a driver wait — withci/autoresearch/test_timing_drift.py(#3768) ready to measure it once a board is back on the bench.fix(core): adaptive yield in show()'s refresh throttle (FastLED#3762, f…
fix(task): clamp the SYSTEM yield to the caller's budget; drop dead n…
zackees commentedon Aug 20, 2026
Burn-down disposition: COMPLETED
The actionable scope of this issue landed in two merged PRs:
show()/showColor()'s unconditional deep yield with the shared adaptive throttle:NetworkDetector::isAnyNetworkActive()gates the deep-yield tier, and the final wait spins insideFastLED.setWaitSpinBudgetUs()so a whole RTOS tick is not always charged.task::run()honor the caller's remaining microsecond budget and removed the deadICoroutineRuntime::needsDeepYield()API, its weaker WiFi-only detector, and the orphaned ESP WiFi dependency.Current
src/FastLED.cpp.hppandsrc/fl/task/executor.cpp.hppcontain those behaviors. The remaining threshold choice is intentionally user-tunable: 250 us favors network progress, while a tick-sized spin budget favors tighter timing.Important correction from the issue thread: the refresh throttle was not the root cause of #2994 because that reproducer's 5 ms cadence never engages the 1.25 ms throttle. #2994 remains a separate, deferred hardware-timing investigation; it is not a reason to keep this already-fixed deep-yield issue open.