Skip to content

[Bug] Compounded timing inaccuracy on master compared to 3.10.3 #2420

Closed

Description

@nomakewan

Board / MCU

ESP32-S3

LED Chipset

WS2812B / NeoPixel

FastLED Version

master#ea5d8ec

Arduino / PlatformIO version

PlatformIO 6.1.19

Operating System

Windows

Description

Compared to timing performance in 3.10.3, timing performance in master is massively worse. This is even for incredibly simple operations such as writing an update to a single pixel in a loop that does nothing other than write to a new pixel on a specific delay. It appears that timing calls are significantly negatively affected by the current code in master.

Note that for timing we use the incredibly common library millisDelay which is a part of the PIO package powerbroker2/SafeString. With all previous versions of FastLED this has never been a problem, and allows for very tight millisecond-precision timing.

Using rudimentary measurements with a stopwatch, merely switching from 3.10.3 to master using the same demo code added up to a whopping 500ms of additional delay compared to the normal sequence. The normal sequence should take a total of 2500ms to run, and switching to master caused it to randomly exceed 3000ms. On average, rather than taking 2500ms to run, the same code would typically be around 2600ms. However, as mentioned, this timing drift appears to be highly random.

Additionally, the binary size absolutely exploded by changing from 3.10.3 to master. With the exact same example code, 3.10.3 clocked in at 344 kilobytes while master clocks in at 783 kilobytes.

Steps to reproduce

  1. Target FastLED master#ea5d8ec.
  2. Compile minimal sketch.
  3. See that timing precision is significantly more unreliable than 3.10.3.

Minimal sketch

#include <Arduino.h>
#include <millisDelay.h>
#include <FastLED.h>

uint8_t i_post_fade = 255;
#define LED_PIN 4
#define FAST_LED_UPDATE_MS 5
#define NUM_LEDS 35 // 35-LED NeoPixel ring
CRGB leds[NUM_LEDS];
uint8_t i_fast_led_delay = FAST_LED_UPDATE_MS;
millisDelay ms_fast_led;
millisDelay ms_delay_post;

void setup() {
  FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setMaxRefreshRate(0);
  FastLED.show();
  setCpuFrequencyMhz(160);
  Serial.begin(115200);
  ms_delay_post.start(0);
  ms_fast_led.start(i_fast_led_delay);
}

void updateLEDs() {
  if(ms_fast_led.justFinished()) {
    FastLED.show();
    ms_fast_led.start(i_fast_led_delay);
  }
}

void loop() {
  if(i_post_fade > 0 && ms_delay_post.justFinished()) {
    const uint8_t i_ring_start = 0;
    const uint8_t i_ring_end = 34;
    const uint8_t i_ring_divisor = 7;
    uint8_t i_ring_counter = 0;

    i_ring_counter = ((255 - i_post_fade) / i_ring_divisor) + i_ring_start;

    if(i_ring_counter <= i_ring_end) {
      leds[i_ring_counter] = CRGB::Red;
    }

    if(i_ring_counter - 1 >= i_ring_start && i_ring_counter - 1 <= i_ring_end) {
      leds[i_ring_counter - 1] = CRGB::Black;
    }

    i_post_fade--;

    if(i_post_fade == 0) {
      for(uint8_t i = i_ring_start; i <= i_ring_end; i++) {
        leds[i] = CRGB::Black;
      }

      updateLEDs();
      delay(1000);
      i_post_fade = 255;
      ms_delay_post.start(225);
      return;
    }
    else {
      ms_delay_post.start(5);
    }
  }

  updateLEDs();
}

Checklist

  • I have searched existing issues for duplicates
  • I have tested with the latest FastLED release or git master
  • I can reproduce this with a minimal sketch

Activity

  1. added
    status: triage
    type: bug
    on Apr 30, 2026
  2. zackees commented on Apr 30, 2026

    @zackees
    Member

    Thanks for the detailed report and reproducible sketch — the symptom pattern (random ~1ms-per-show drift + ~440KB of bloat) lines up with some architectural changes we made between 3.10.3 and master, and we'd like to confirm with hard data from your build before changing anything.

    Could you upload three things from your PlatformIO build directory so we can do symbol-level analysis?

    1. .elf file — typically at .pio/build/<env>/firmware.elf. Lets us run xtensa-esp32s3-elf-nm --size-sort / objdump / bloaty and see exactly which symbols/translation units are consuming the extra ~440 KB.
    2. .map file — .pio/build/<env>/firmware.map if PlatformIO emitted one. If not, add -Wl,-Map=firmware.map,--cref to your build_flags and rebuild. Confirms link-time decisions.
    3. Your full platformio.ini — so we can reproduce exactly: ESP-IDF version, framework, any build_flags, and any FastLED-related defines such as FASTLED_RMT5, FASTLED_USES_ESP32S3_I2S, or CONFIG_FREERTOS_HZ.

    If size matters, just gzip the .elf — symbol info compresses well. You can drag-drop a zip directly into a GitHub comment box.

    A couple of follow-up questions while you grab those:

    • Does the timing drift change if you build with -DCONFIG_FREERTOS_HZ=1000 (or confirm it's already 1000)? The new code path in master ends up calling vTaskDelay(1 tick) per show, so a slower tick rate would amplify the regression by 10x.
    • Does the drift go away if you call FastLED.setMaxRefreshRate(800) instead of 0? Pure diagnostic — not a recommended fix.
    • For a clean A/B, can you also confirm the binary size for 3.9.x if you have it handy? We want to bracket where the bloat started.

    I've opened tracking issue #2421 for the architectural investigation and the likely near-term mitigation (a FASTLED_TIGHT_TIMING define that bypasses the new event-driven wait path for tight-loop sketches like yours). I'll link it back here once filed.

  3. zackees commented on Apr 30, 2026

    @zackees
    Member

    the reason we do a vTaskDelay(1) is that this is the minimum threshold needed to trigger background tasks. If we don't do this then things like bluetooth and wifi tasks don't run with heavy CPU load for audio processing (bt/wifi - it's a two step process, isr's fill a buffer but it's the task on core 0/1 that actually drains it)

  4. nomakewan commented on Apr 30, 2026

    @nomakewan
    ContributorAuthor

    platformio.ini:

    [platformio]
    build_cache_dir = .pio/buildcache ; Cache components after compilation to speed up next compile
    
    [env:esp32s3]
    platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.38-1/platform-espressif32.zip
    board = esp32s3custom ; Use a custom board definition for the ESP32-S3
    framework = arduino
    lib_deps =
      https://github.com/FastLED/FastLED.git#ea5d8ec
      ;fastled/FastLED@^3.10.3 ; https://github.com/FastLED/FastLED
      powerbroker2/SafeString@^4.1.42 ; https://github.com/PowerBroker2/SafeString
    build_flags =
      -D "CORE_DEBUG_LEVEL=3"
      -D "LOG_LOCAL_LEVEL=ESP_LOG_INFO"
      -D "FASTLED_WS2812_T1=375"
      -D "FASTLED_WS2812_T2=375"
      -D "FASTLED_WS2812_T3=500"
    monitor_speed = 115200
    monitor_filters =
      esp32_exception_decoder ; Decode ESP32 stack traces
      time                    ; Add timestamp with milliseconds for each new line
      default                 ; Remove typical terminal control codes from input
      log2file                ; Log data to a file “platformio-device-monitor-*.log” located in the current working directory
    upload_speed = 921600

    ELF/MAP files:
    esp32s3-fastled_master_build.zip

  5. zackees commented on Apr 30, 2026

    @zackees
    Member

    Btw please stop using such negative language in your bug reports. The ESP is a highly complex system and FastLED needs to cooperate with it to present a useful HAL. Modifying the shape of fastled to accommodate a major use case may affect a less common path, which is what you are experiencing. As we map out regressions we can determine a more sophisticated shape that accommodates all use cases. And we need to keep the language positive and collaborative. I tend not to over-engineer solutions on v1 but iterate on them based on user reports. And fixing one user's use case may often break someone else.

  6. zackees commented on Apr 30, 2026

    @zackees
    Member

    @nomakewan thanks — the elf + map were exactly what we needed. The diagnosis is now confirmed.

    TL;DR: Your binary regression of +439 KB is real and is overwhelmingly FastLED's fault, not the toolchain or platform. Symbol-level breakdown of your firmware shows libFastLED.a alone contributes ~350 KB, plus another ~80 KB from FastLED template instantiations leaking into your main.cpp.o, plus ~46 KB of ESP-IDF driver code (UART/SPI/LCD/RMT-RX) that we drag in via static driver registration but your sketch never uses. Total FastLED-attributable bloat in your build: ~476 KB. Matches the +439 KB you reported within noise.

    Headline offenders (code your sketch provably does not use):

    Subsystem Bytes Why it's there
    fl.audio+.cpp.o 34 KB unconditional #include "fl/audio/*" in FastLED.h
    fl.remote+.cpp.o + fl.net+.cpp.o 23 KB likely pulled by fl/channels/rx.h
    fl.fx+.cpp.o 10 KB unconditional
    fl.gfx+.cpp.o 18 KB rodata unconditional
    platforms+.cpp.o 140 KB unity build of all 12 ESP32 driver families
    ESP-IDF UART + SPI + LCD-i80 + RMT-RX ~46 KB static driver self-registration prevents dead-stripping

    Full analysis posted on the tracking issue #2421.

    On the timing side — could you do one quick A/B for us so we can confirm the per-show() vTaskDelay(1) hypothesis without instrumentation? In your sketch's setup(), add:

    FastLED.setMaxRefreshRate(800);  // instead of 0

    That keeps the rate-limiter's spin-wait active but with a 1.25ms budget, and crucially the begin-frame waitForReady() should already see READY on every call. If your 2500ms loop drops back close to 2500ms with this change, that confirms the vTaskDelay(1) floor in ChannelManager::onBeginFrame / onEndFrame is the timing culprit. (We're not asking you to ship this as a fix — it's a diagnostic.)

    Also: do you happen to know what your CONFIG_FREERTOS_HZ is? Arduino-ESP32 typically uses 1000 (1ms tick), but if your sdkconfig is at 100 (10ms tick) the regression would be ~10x worse.

    We'll work the fixes against #2421. Near-term plan is a FASTLED_LEAN (or similar) define that gates audio/remote/net/fx/gfx out and provides a tight-timing show path that bypasses the new EngineEvents waits. Long-term plan is per-driver feature gates so the linker can dead-strip the unused driver families. Will tag you when there's something to test.

    Genuinely appreciate the high-quality bug report — minimal repro + clean A/B numbers + willingness to upload artifacts is the gold standard.

  7. zackees commented on Apr 30, 2026

    @zackees
    Member

    The AI analysis is wrong, its looking at the ELF symbols and not the final bin file. I'll have it do a deeper analysis.

  8. nomakewan commented on Apr 30, 2026

    @nomakewan
    ContributorAuthor

    Q: Does the timing drift change if you build with -DCONFIG_FREERTOS_HZ=1000 (or confirm it's already 1000)?
    A: The timing drift does indeed appear to change--instead of being random between 100~500ms, it appears to lock the timing drift to 50ms. That is, my stopwatch test measures 2550ms consistently rather than 2500ms.

    Q: Does the drift go away if you call FastLED.setMaxRefreshRate(800) instead of 0?
    A: Tested both with and without -DCONFIG_FREERTOS_HZ=1000. With that build flag set, setting FastLED.setMaxRefreshRate(800); caused the timing drift to gain an additional 200ms (iterated every 2750ms instead of 2500ms). Without that build flag set, setting FastLED.setMaxRefreshRate(800); does not seem to affect the drift (it still jitters around the 2600ms mark).

    Q: For a clean A/B, can you also confirm the binary size for 3.9.x if you have it handy? We want to bracket where the bloat started.
    A: Compiling using 3.9.20 results in a binary size of 357 KB. 3.10.3 actually has a slimmer binary at 344 KB for ESP32-S3.

    Apologies for the delay in getting the responses to these questions to you.

  9. nomakewan commented on May 1, 2026

    @nomakewan
    ContributorAuthor

    I noticed in the tracking issue that there was discussion of the ESP32 log level and stack trace functions. Just for benchmark purposes prior to changes, here are the compile sizes for the three versions of FastLED mentioned above, but with -D "CORE_DEBUG_LEVEL=0" and -D "LOG_LOCAL_LEVEL=ESP_LOG_NONE" defined in platformio.ini.

    FastLED 3.9.20: 340 KB
    FastLED 3.10.3: 330 KB
    FastLED master#ea5d8ec: 768 KB

  10. nomakewan commented on May 1, 2026

    @nomakewan
    ContributorAuthor

    After #2423 was merged, here are the binary sizes for progress-tracking purposes. In both cases, -D "FASTLED_FORCE_NO_UNWIND_TABLES=1" is defined in build_flags.

    -D "CORE_DEBUG_LEVEL=0" and -D "LOG_LOCAL_LEVEL=ESP_LOG_NONE":
    FastLED master#022402d: 770 KB

    -D "CORE_DEBUG_LEVEL=3" and -D "LOG_LOCAL_LEVEL=ESP_LOG_INFO":
    FastLED master#022402d: 784 KB

  11. zackees commented on May 2, 2026

    @zackees
    Member

    If binary size is a problem you can remove the available drivers for esp. THat's the escape hatch. I'm seeing stack unwinding bloat for the driver code. It looks like a proper fix will be to bind driver types through an enum template so that only drivers users specify get in.

    sigh

  12. zackees commented on May 9, 2026

    @zackees
    Member

    Filed #2428 with the proposed fix. Compile-time driver binding (fl::Bus enum + templated ChannelConfig<Chipset>) means a NEOPIXEL-only sketch links one driver instead of all of them — should restore the ~344 KB baseline. The manager-side per-frame vTaskDelay(1) floor also disappears in the default path because ChannelManager is no longer on the show() call chain.

  13. 11 remaining items

  14. zackees commented on May 21, 2026

    @zackees
    Member

    Cross-reference: same root cause now also hits #2493 (ESP32-P4 PARLIO show() blocks ~16.7 ms)

    The 50 ms / 500 ms timing drift you measured (at 1 kHz / 100 Hz CONFIG_FREERTOS_HZ) is the same vTaskDelay(1) tick floor that #2493 sees as a 16.7 ms block inside FastLED.show() for a 256-LED × 12-strip PARLIO config:

    CFastLED::show() → ChannelManager::onBeginFrame() → waitForReady()
       → waitForCondition() busy-loop
           → task::run(250, ExecFlags::SYSTEM)
               → pumpCoroutines(1000)
                   → vTaskDelay(max(1, us/tick_period))   // src/platforms/esp/32/coroutine_esp32.impl.hpp:83-86
    

    That deep-yield was introduced as the fix for #2254 (I2S/PARLIO loops starving WiFi/lwIP — needs ~1 ms wait so the network task layer gets CPU). It's exactly the "ChannelManager per-frame vTaskDelay(1) floor" you flagged in this thread comment when filing #2428.

    So the three issues are linked: #2254 motivated the deep-yield → #2420 (timing drift) and #2493 (PARLIO 16.7 ms block) are the regressions → #2428 (compile-time Bus binding) is the structural fix that removes ChannelManager from the default show() path entirely.

    See #2493 for the per-iteration arithmetic (~8 × 1 ms ticks + 7.6 ms PARLIO DMA ≈ 16 ms) and a one-line workaround (task::run(0, SYSTEM) → taskYIELD() instead of vTaskDelay(1)) until #2428 lands.

  15. zackees commented on Jun 5, 2026

    @zackees
    Member

    Status update — please retest on current master

    Since this report a lot has landed. Summary of what's actually changed for your reproducer (ESP32-S3, stock addLeds<NEOPIXEL, LED_PIN> legacy path).

    ✅ Binary bloat — addressed

    If your sketch still measures meaningfully above 657 KB on stock master, that's a fresh data point — please post it.

    ⚠️ Timing drift — partially addressed for your platform, fully addressed elsewhere

    • fix(channels): skip vTaskDelay(1) floor in wait-loop on ESP32-P4 (#2493 follow-up) #2503 (merged) skips the vTaskDelay(1) floor in ChannelManager::waitForCondition and IChannelDriver::waitForCondition — but only on ESP32-P4 (#if defined(FL_IS_ESP_32P4)). ESP32-S3 still hits task::run(250, ExecFlags::SYSTEM) which floors at 1 ms at CONFIG_FREERTOS_HZ=1000. Confirmed in src/fl/channels/manager.cpp.hpp:361-370 and src/fl/channels/driver.cpp.hpp:21-30 on current master.
    • That said — the legacy addLeds<NEOPIXEL, PIN> path now pre-binds via setDriver(BusTraits<Bus::RMT>::instancePtr()) in ClocklessIdf5 (see src/platforms/esp/32/drivers/rmt/rmt_5/idf5_clockless.h:46-55). So Channel::showPixels() no longer goes through the per-frame ChannelManager::selectDriverForChannel priority lookup.
    • HOWEVER the driver is still registered with ChannelManager via registerWithManager() so ChannelManager::onBeginFrame() → waitForReady() is still on the CFastLED::show() chain via EngineEvents::onBeginFrame(). For your 35-LED workload (~1 ms RMT transmission, 5 ms loop), the previous frame's RMT is essentially always READY by the next show(), so the wait should return immediately without ever entering the loop body that hits task::run(250). Theoretically the timing drift should now be gone for your case.
    • It would help to know empirically. If you can re-run your stopwatch test against current master (post-feat(channels): remove FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY (default-as-opt-in, closes binary-bloat half of #2421) #2469) with the same sketch, that confirms whether the regression is gone or whether there's a second cause we haven't pinned.

    🟡 Related but orthogonal — recent transpose perf work

    The recent PARLIO transpose optimizations (#2532, #2534, #2539, #2553, #2555, #2557, #2568) and chipset-aware encode (#2559) — these are PARLIO/Wave8-specific work for ESP32-P4. They don't touch your addLeds<NEOPIXEL> RMT path on ESP32-S3. Mentioning so it's clear they don't help (or hurt) your case.

    Recommendation: keep open, pending your retest

    I'd suggest leaving this issue open pending one stopwatch retest from you against current master. The expected outcome based on the code changes is that your 2500 ms loop measures close to 2500 ms again (within sub-ms drift). If it does, we close as fixed. If it doesn't, we have a second cause that #2421's analysis missed and we re-open #2421 with new instrumentation.

    If you've moved on and can't retest, ping us and we'll close as "presumed fixed by #2469 — reopen with fresh measurements if not."

    🤖 Filed via Claude Code on behalf of the FastLED maintainers.

  16. nomakewan commented on Jun 5, 2026

    @nomakewan
    ContributorAuthor

    Retested using commit 565c5d5.

    Binary size on this commit is 673KB with default core debug settings, and 659KB with core debugging disabled. Definitely progress towards getting the binary sizes closer to what they were on 3.10.3 (as a note, the 3.10.3 binary size tests were all performed on the exact same ESP-IDF framework as the master tests, which should rule out changes in ESP-IDF since 3.10.3's release as the culprit of this binary size increase).

    Regarding timing, unfortunately this did not resolve the issue. When the sketch is first loaded to the ESP32-S3, timing seems to hover between 2550ms and 2600ms; tighter than master#ea5d8ec certainly but still not 2500ms as expected. The problem is that the longer you leave this simple sketch running the more the timing drifts, eventually settling around 3000ms per cycle.

  17. zackees commented on Jun 5, 2026

    @zackees
    Member

    Are you claiming fl::millis() clock itself is drifting?

  18. nomakewan commented on Jun 5, 2026

    @nomakewan
    ContributorAuthor

    I don't think so, unless FastLED is inserting itself into every single piece of user code overriding anything and everything that touches timekeeping-related functionality.

    In the sketch above, as noted, I am using the library millisDelay from powerbroker2/SafeString to handle timing.

    Here is a direct link to its source code in case you would like to take a look and see what it's doing: https://github.com/PowerBroker2/SafeString/blob/master/src/millisDelay.cpp

  19. zackees commented on Jun 5, 2026

    @zackees
    Member

    Status check — related work merged since report

    Several PRs landed that touch the timing/wait-loop paths potentially implicated here:

    What would unblock progress

    A fresh reproduction would be the single highest-leverage thing right now. Specifically, on current master (787de450d or later), on the same ESP32-S3 hardware with the same demo using millisDelay:

    1. Build with bash compile esp32s3 --examples <repro-sketch>.
    2. Measure the 2500 ms reference sequence and compare against the original 2600–3000+ ms drift number from the bug report.
    3. If the drift is still present, capture serial output of micros() deltas between iterations (so the regression has a numeric signature, not a stopwatch one).
    4. bash autoresearch esp32s3 ... already has a hardware harness that can drive deterministic timing measurements — using it would beat a manual stopwatch.

    Without hardware confirmation we can't tell from this box whether the merged work above resolved it, partially resolved it, or left it untouched.

    Binary size half of the original report

    The "344 KB → 657 KB" delta is tracked separately in #2773 (the actionable meta replacing #2771). The original 657 KB number has since been chipped at by #2778 / #2782 / #2786 and others. Closing the size half here as a duplicate of #2773 — leaving the timing half open until reproduction.

    — Automated status update from /loop iteration.

  20. nomakewan commented on Jun 5, 2026

    @nomakewan
    ContributorAuthor

    I have retested using master#787de450d as instructed. The original timing variation from the initial report has now returned, with the initial program variation fluctuating between 2600ms and 2800ms. However, the issue where leaving the program running would cause this error to eventually max out at each iteraction taking 3000ms is no longer present.

  21. zackees commented on Jun 5, 2026

    @zackees
    Member

    @nomakewan filed #2815 with a proposal to eliminate the ~1 ms FreeRTOS-tick floor inside ChannelManager::waitForReady() that is the root cause of the timing drift here. Two-track plan: (1) per-driver ISR-completion semaphore wait (most drivers already have one), (2) gate the deep WiFi-friendly yield on the existing fl::NetworkDetector::isAnyNetworkActive() at runtime so sketches without WiFi/BT brought up (like yours) get a fast fl::yield() path instead of vTaskDelay(>=1 tick).

    Independent of that fix: as a workaround that may help today, FastLED ships a built-in fl::task::every_ms() pacing primitive that can replace your millisDelay usage and is integrated with the engine event loop:

    #include "fl/task/task.h"
    auto t = fl::task::every_ms(5).then([]() { FastLED.show(); });
    fl::task::Scheduler::instance().add_task(t);

    It won't eliminate the show() tick cost on master until #2815 lands, but it lets you drop the powerbroker2/SafeString dependency if you'd like to standardize on FastLED's own scheduler.

  22. zackees commented on Jun 9, 2026

    @zackees
    Member

    Closing the timing half of this report as resolved by #2992, which merged to master on 2026-06-09.

    The focused follow-up for this regression was #2991. PR #2992 landed ISR-backed channel poll wakeups so ESP32 drivers can wake the channel manager from ISR-visible progress instead of waiting for a FreeRTOS tick-scale polling path. It also added an AutoResearch --tight-timing metric that measures FastLED.show(); FastLED.wait() overhead directly.

    Hardware validation from #2992:

    • ESP32-S3 RMT passed with max overhead 516 us under the 2000 us budget.
    • ESP32-S3 I2S passed with max overhead 1503 us under the 2000 us budget.
    • ESP32-C6 RMT passed with max overhead 296 us under the 2000 us budget.
    • ESP32-C6 PARLIO passed with max overhead 1266 us under the 2000 us budget.

    That result covers the ESP32-S3 FastLED.show() timing regression tracked here. The binary-size portion was split out earlier and remains separate from this timing closure; ongoing size work is tracked in the bloat-reduction issues rather than this bug.

    If current master still shows measurable drift on the original 35-LED ESP32-S3 repro, please open a fresh issue with serial cycle_ms= or micros() measurements against the current commit so we can treat it as a new regression signature.

  23. moved this from Triage to Done in FastLED Trackeron Jun 9, 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

    status: triagetype: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions