Skip to content

ESP32-S3 binary size: 657 KB on master vs 344 KB on 3.10.3 — remaining +313 KB delta breakdown #2473

Closed

Description

@zackees

Summary

Follow-up to #2420 / #2421 / #2424 / #2428. After the recent fixes landed (channels-as-default-opt-in driver registry, audio/net/video/fx/gfx eh_frame cleanup, FL_NO_UNWIND via #2423), the ESP32-S3 NEOPIXEL Blink binary is 657,072 B — that's the structural floor of the new Channel API. The 3.10.3 baseline on the same minimal sketch was ~344 KB, so we still carry a +313 KB delta. This issue tracks where that residual lives so we can decide what (if anything) to chip away at next.

Measured on

Item Value
Branch feat/remove-legacy-driver-registry-macro
Commit 4127a0c8da
Sketch examples/Blink/Blink.ino (single NEOPIXEL controller, pin 3)
Board esp32-s3-devkitc-1 (Espressif ESP32-S3-DevKitC-1-N8, 8 MB flash, no PSRAM)
Toolchain xtensa-esp-elf-gcc 14.2.0
Build path PlatformIO 6.1.19 → pio run -e esp32s3 (fbuild hangs on cold ESP32 builds — see fbuild#117)
firmware.bin 657,072 B
firmware.elf 38,516,728 B (with DWARF)
firmware.map 28,136,474 B

Section sizes (xtensa-esp32s3-elf-size -A)

Section Bytes vs reporter's #2420 (master#ea5d8ec, 783 KB bin)
.flash.text 260,444 −85,456 (was 345,900)
.flash.rodata 317,064 −42,144 (was 359,208)
.iram0.text 64,527 −15,012 (was 79,539)
.dram0.data 13,584 −2,532
.dram0.bss 11,368 —

Symbol categories (xtensa-esp32s3-elf-nm --print-size -C)

Category Bytes KB Symbols
OTHER (Arduino core, ESP-IDF init, debug, crypto, partition) 130,315 127.3 1,834
FastLED (fl::*, CFastLED, CLEDController, PixelController) 71,453 69.8 801
ESP-IDF/HAL (rmt, gdma, tlsf, mmu, nvs, rtc, panic, coredump) 57,563 56.2 428
libc/runtime (printf family, dtoa, ieee754_pow, get_arg) 57,354 56.0 600
UART/Serial (Arduino HardwareSerial — for console, not FastLED) 25,034 24.4 186
FreeRTOS 12,229 11.9 58
App (setup/loop/main) 2,122 2.1 43

Subsystems that #2421/#2424 fixed (verified GC'd now)

fl::audio        0 bytes   (was 34 KB orphan eh_frame)
fl::video        0 bytes
fl::net          0 bytes
fl::http         0 bytes
fl::remote       0 bytes
fl::fx           0 bytes
fl::gfx          0 bytes
fl::Font         0 bytes
AudioManager     0 bytes
BleDevice        0 bytes
formatJsonResponse 0 bytes
ChunkedReader    0 bytes
fl::asio        32 bytes   (one residual stub symbol)

Driver families that #2428 fixed (verified — only RMT survives)

ChannelEngineRMT*Impl      14,301 B   <- needed (NEOPIXEL -> RMT)
Rmt5* (encoder/peripheral)  5,691 B   <- needed
ClocklessIdf5                 991 B   <- needed
BusTraits                      16 B
ChannelEngineSpi (vtable)      88 B   (typeinfo only - no code)
ChannelEngineUART               0 B
ChannelEngineI2S                0 B
ChannelDriverLcdSpi             0 B
ChannelDriverLcdClockless       0 B
ChannelDriverParlio             0 B

ESP-IDF drag-ins that #2428 fixed (was ~46 KB):

rmt_new_tx_channel          2,072 B   <- needed
uart_driver_install           711 B   <- Arduino HardwareSerial (Serial.begin), not FastLED
rmt_rx                          0 B
spi_master                      0 B
esp_lcd_panel_io_i80            0 B
esp_lcd_panel_io_spi            0 B
i2s_                            0 B

Where the FastLED 70 KB actually lives

Subsystem Bytes KB Symbols
RMT (encoder, peripheral impl, memory mgr, buffer pool) 28,154 27.5 114
Channels (Channel::showPixels, ChipsetTiming, ChannelData) 13,663 13.3 170
Other fl:: (lifecycle, Singleton, misc) 7,240 7.1 192
PixelIterator / PixelController 4,248 4.1 72
ChannelManager 3,905 3.8 31
fl::basic_string 2,827 2.8 24
fl::vector_basic 2,568 2.5 37
Gamma LUT (ProgmemLUT16<GammaEval16<...>, 256>::kData = 512 B table + accessors) 2,159 2.1 32
fl::task::Scheduler 1,928 1.9 30
ChannelEvents / EngineEvents 1,316 1.3 34
ClocklessIdf5 wrapper 1,107 1.1 16
shared_ptr / weak_ptr / RefCount 506 0.5 12
variant 106 0.1 5

Top 12 single largest FastLED symbols (where reduction would have biggest impact)

Bytes Symbol
5,013 fl::Channel::showPixels(PixelController<GRB, 1, 0xFFFFFFFF>&)
4,590 fl::ChannelEngineRMTImpl::createChannel(...)
2,708 fl::RmtMemoryManager::allocateTx(uint8_t, bool, bool)
2,160 fl::ChannelEngineRMTImpl::reconfigureForNetwork()
1,528 fl::detail::Rmt5EncoderImpl::initialize(ChipsetTiming, unsigned long)
1,151 fl::basic_string::write(const char*, unsigned)
948 fl::ChannelEngineRMTImpl::processPendingChannels()
826 fl::RmtMemoryManager::calculateMemoryBlocks(bool)
738 fl::ChannelEngineRMTImpl::configureChannel(...)
676 fl::ChannelManager::selectDriverForChannel(shared_ptr<ChannelData>, string)
606 fl::detail::Rmt5PeripheralESPImpl::waitAllDone(void*, unsigned long)
564 fl::ChannelEngineRMTImpl::destroyChannel(...)

Top 5 NON-FastLED single largest symbols

Bytes Symbol Source
11,309 _vfprintf_r newlib
11,118 _svfprintf_r newlib
7,337 _svfiprintf_r newlib
7,265 _vfiprintf_r newlib
4,096 port_IntStack FreeRTOS

→ ~36 KB of printf-family is being dragged in. Likely culprit: FL_LOG / FL_WARN / FL_ERROR macros emit format strings that ODR-use the full _vfprintf_r family. Worth checking whether we can route logging through a smaller printf-substitute on embedded targets, or gate verbose log macros behind a release-build define.

Reduction hypotheses (in rough priority order)

  1. Channel::showPixels is 5 KB for a single GRB instantiation. The map shows just one PixelController template instantiation in the final binary — that's fine for cold-start size, but the function itself is large. Worth checking if it's pulling in the gamma scaling, dither, and brightness paths even when the user hasn't called setBrightness/setGamma. A tiered fast-path (no-brightness, no-gamma, no-dither) could probably cut this in half for the default case.

  2. ChannelEngineRMTImpl::createChannel is 4.6 KB and reconfigureForNetwork is 2.2 KB. These look like they handle the full driver lifecycle for hot-plug add/remove of channels. A NEOPIXEL-only sketch with addLeds<> at static init never reconfigures the network — could we split a "one-shot setup" path from the dynamic reconfigure path and only link the dynamic one when the user actually calls removeLeds() / dynamic add?

  3. RmtMemoryManager is 4.5 KB across allocateTx/calculateMemoryBlocks/freeDMA. The dynamic memory-block planner is rich. For a single fixed-strip sketch, a compile-time-fixed memory block count would eliminate the planner.

  4. printf family ~36 KB. Likely from FL_LOG / FL_WARN. Two options:

    • Gate all FL_LOG_* behind FASTLED_LOG_LEVEL (default off in release)
    • Replace printf-style formatting in those macros with a minimal hand-rolled formatter that doesn't pull in _vfprintf_r
  5. fl::basic_string and fl::vector_basic together = 5.4 KB. Could be reduced if we audit where strings are constructed at runtime in non-error paths. ChannelManager::selectDriverForChannel takes a fl::string by const-ref — checking whether the caller actually needs a string here or if a string_view / enum would suffice.

  6. fl::task::Scheduler::warn_no_then is 476 B for an error-path warning. Cheap fix: move the format string and printf call out-of-line into a single __attribute__((cold,noinline)) helper.

Reproduction

# Branch: feat/remove-legacy-driver-registry-macro @ 4127a0c8da
bash compile esp32s3 --examples Blink
# OR (fbuild #117 workaround):
cd .build/pio/esp32s3 && .venv/Scripts/pio run -e esp32s3

ELF=.pio/build/esp32s3/firmware.elf
xtensa-esp32s3-elf-size -A "$ELF"
xtensa-esp32s3-elf-nm --print-size --size-sort --reverse-sort -C "$ELF" | head -40

Related

Out of scope (but worth mentioning)

fbuild v2.2.3 reliably hangs on cold ESP32-S3 builds at the post-framework-libs handoff (fbuild#117 — closed as "instrumentation added" without an actual fix). This forced the symbol analysis above to run through pio run directly. Not strictly a FastLED issue, but worth a heads-up since it complicates measurement workflows for anyone trying to reproduce these numbers.

Activity

  1. zackees commented on May 12, 2026

    @zackees
    MemberAuthor

    ⚠️ Correction: the "+313 KB structural delta" is misleading — 231 KB of it is unstripped .eh_frame

    I did a full per-archive map-based audit and the picture is materially worse than the original symbol-level breakdown above suggested. Symbol-level nm --print-size only counts symbols with explicit size annotations, which misses .eh_frame entirely (it has no per-symbol attribution) and misses the merged-string pool (.rodata.str1.1).

    Where the 657 KB actually lives (map-based, per output section)

    Bucket Bytes KB % of bin
    .eh_frame orphan unwind metadata 236,932 231 36.0%
    Merged-string pool (.rodata.str1.1 — FL_LOG / FL_WARN format strings + RTTI demangled names) ~55,190 54 8.4%
    FastLED actual code (.flash.text from libFastLED.a) 71,416 70 10.9%
    libc/newlib (_vfprintf_r family) 60,300 59 9.2%
    ESP-IDF + FreeRTOS code + tables ~150,000 147 22.8%
    Arduino-core ~26,000 25 4.0%
    Vtables / jump tables / RTTI / real rodata ~50,000 49 7.6%

    .eh_frame per archive in the binary

    libFastLED.a       168,772 bytes   <- biggest single offender
    libstdc++.a         56,148
    libnvs_flash.a       4,068
    libFrameworkArduino  3,240
    libFS.a              1,628
    libSD.a              1,092
    libSPI.a               728
    libgcc.a               688
    main.cpp.o             424
    libcxx.a               140
    TOTAL              236,932 bytes (231 KB)
    

    .eh_frame per FastLED unity TU

    platforms+.cpp.o    34,960   <- has FL_NO_UNWIND_BEGIN applied, still ships 35 KB
    fl.audio+.cpp.o     34,324
    fl.gfx+.cpp.o       17,184
    fl.stl+.cpp.o       16,048
    fl.channels+.cpp.o  15,448
    fl.net+.cpp.o       10,612
    third_party+.cpp.o  10,008
    fl.fx+.cpp.o         9,668
    fl.math+.cpp.o       6,196
    fl.system+.cpp.o     3,896
    fl.task+.cpp.o       3,776
    src.cpp.o            2,688
    fl.log+.cpp.o        2,172
    fl.video+.cpp.o      1,792
    

    Why FL_NOEXCEPT and FL_NO_UNWIND aren't preventing this

    Three cascading failures:

    (1) FL_NOEXCEPT is currently a no-op

    src/fl/stl/noexcept.h:7-9:

    #ifndef FL_NOEXCEPT
    #define FL_NOEXCEPT
    #endif

    Header comment: "noexcept was causing too many platform compatibility issues (AVR, WASM, etc.) so it is disabled everywhere until a robust cross-platform solution is found."

    Even if FL_NOEXCEPT expanded to real noexcept, that's a C++ language contract and does not suppress -fasynchronous-unwind-tables codegen. noexcept and .eh_frame are independent.

    (2) FL_NO_UNWIND_BEGIN disables the wrong flag

    src/fl/stl/compiler_control.h:330:

    #define FL_NO_UNWIND_BEGIN _Pragma("GCC push_options") _Pragma("GCC optimize(\"no-unwind-tables\")")

    This disables -funwind-tables (default OFF) but does NOT disable -fasynchronous-unwind-tables (default ON on ESP32 because the panic handler needs backtraces).

    Both flags produce .eh_frame. Disabling only the off-by-default one accomplishes nothing on ESP32. That is why platforms+.cpp.o — the one TU that IS wrapped with FL_NO_UNWIND_BEGIN — still ships 34,960 B of eh_frame in the binary.

    The pragma needed to actually strip it would be:

    _Pragma("GCC optimize(\"no-unwind-tables,no-asynchronous-unwind-tables\")")

    …and even that is unreliable because GCC's optimize attribute is officially documented as intended for -O* levels; for non-optimization codegen flags the behavior is "may or may not propagate" depending on GCC version. The robust mechanism is to pass -fno-asynchronous-unwind-tables -fno-unwind-tables on the compile command line for every TU, not via pragma.

    (3) FL_NO_UNWIND_BEGIN is wrapped around only 2 of 15+ FastLED unity TUs

    Files that currently have FL_NO_UNWIND_BEGIN/_END:

    src/platforms/esp/32/_build.cpp.hpp:8
    src/platforms/esp/32/drivers/_build.cpp.hpp:21
    

    All these other unity build headers have no wrapping at all:

    src/fl/audio/_build.cpp.hpp       -> 34,324 B eh_frame
    src/fl/gfx/_build.cpp.hpp         -> 17,184 B
    src/fl/stl/_build.cpp.hpp         -> 16,048 B
    src/fl/channels/_build.cpp.hpp    -> 15,448 B
    src/fl/net/_build.cpp.hpp         -> 10,612 B
    third_party/_build.cpp.hpp        -> 10,008 B
    src/fl/fx/_build.cpp.hpp          ->  9,668 B
    src/fl/math/_build.cpp.hpp        ->  6,196 B
    src/fl/system/_build.cpp.hpp      ->  3,896 B
    src/fl/task/_build.cpp.hpp        ->  3,776 B
    src.cpp.o (top-level FastLED.cpp) ->  2,688 B
    src/fl/log/_build.cpp.hpp         ->  2,172 B
    src/fl/video/_build.cpp.hpp       ->  1,792 B
    

    (4) --gc-sections doesn't reap orphan .eh_frame entries

    Known GNU LD limitation: when --gc-sections strips a .text.foo chunk for a function the linker proves unreachable, the corresponding FDE in .eh_frame is not automatically removed because LD treats .eh_frame as one merged section rather than per-function chunks. This is why audio/net/gfx/fx/video TUs — whose code is provably dead-stripped (nm shows zero fl::audio::* symbols) — still ship their eh_frame metadata.

    ESP-IDF intentionally does not add /DISCARD/ : { *(.eh_frame) } to its linker script because the panic handler needs eh_frame for backtraces.

    What would actually fix it

    The only mechanisms that reliably strip .eh_frame on GCC 14.2.0 for ESP32:

    1. Pass -fno-asynchronous-unwind-tables -fno-unwind-tables as compile flags for every libFastLED.a TU. This needs PIO lib_compile_flags or build-system per-library injection — not a header-level pragma. Estimated savings: ~169 KB (the full libFastLED.a eh_frame).
    2. Compile-time gate on debug builds (when CONFIG_ESP_SYSTEM_PANIC_PRINT_BACKTRACE is on, leave eh_frame in so the panic handler can backtrace through FastLED frames). The existing FL_NO_UNWIND_ACTIVE logic already has the gating right; the macro just doesn't emit the right flag.
    3. Optional: user-facing build flag FASTLED_STRIP_EH_FRAME=1 that injects those compile flags via the library build system.

    Bonus: the merged-strings pool (~55 KB) is mostly FastLED FL_LOG/FL_WARN

    The first input to .flash.rodata is 55,190 bytes attributed to a single template-ctor's .str1.1 (the merged-strings input section) — that's the linker placing the deduplicated string-literal pool there. It contains FL_LOG / FL_WARN / format strings, RTTI demangled names (vtable for fl::ClocklessIdf5<3, TIMING_WS2812_800KHZ, ...>), __FILE__/__func__ literals, and fl::busName(fl::Bus) enum-name table strings.

    Recovery target if we gate the verbose log strings behind a release-mode FASTLED_LOG_LEVEL define: an estimated 30–40 KB. RTTI demangled name strings can be killed with -fno-rtti for the FastLED library, but that breaks typeid() usage anywhere — needs auditing first.

    Revised reduction priorities

    Fix Estimated savings Notes
    Add -fno-asynchronous-unwind-tables to FastLED lib compile flags + apply to all _build.cpp.hpp wrappers ~169 KB Biggest single win. Already half-implemented; just disabling the wrong flag.
    Fix the FL_NO_UNWIND_BEGIN macro to add ,no-asynchronous-unwind-tables (best-effort pragma) partial subset of #1 Cheap but doesn't fully replace the compile-flag approach
    Gate FL_LOG/FL_WARN strings behind a release-mode log level 30-40 KB Same merged-strings pool that was 23 KB in #2424's revised analysis, has grown
    Per-mode template dispatch in loadAndScaleRGBW unknown mentioned in #2426's wrap-up as out-of-scope

    After #1 alone the binary would drop from 657 KB -> ~488 KB. Combined with #3 we are at ~450 KB, within 100 KB of the 3.10.3 baseline. The remaining ~100 KB is the genuine structural cost of the Channel API + RMT engine (which is what the original "structural delta" framing should have referred to).

  2. zackees commented on May 12, 2026

    @zackees
    MemberAuthor

    Quick clarification on the commit reference: the analysis was run on local commit 4127a0c8da of branch feat/remove-legacy-driver-registry-macro, which is byte-for-byte identical to origin/master at 8616873b73 (merged as #2469 — same change, different SHA due to GitHub squash). git diff HEAD origin/master = 0. The numbers reported here represent current master state.

  3. zackees commented on May 12, 2026

    @zackees
    MemberAuthor

    Object-file-level evidence: FL_NO_UNWIND_BEGIN is a no-op on GCC 14.2.0 / Xtensa

    To answer "is the pragma actually doing anything?" directly: I dumped the .eh_frame count from the wrapped TU's .o file before linking. The numbers leave no ambiguity.

    Setup

    src/platforms/esp/32/_build.cpp.hpp wraps every driver include with FL_NO_UNWIND_BEGIN / FL_NO_UNWIND_END:

    #include "fl/stl/compiler_control.h"
    FL_NO_UNWIND_BEGIN
    
    #include "platforms/esp/32/condition_variable_esp32.cpp.hpp"
    #include "platforms/esp/32/init_esp32.cpp.hpp"
    ... (all platform .cpp.hpp's) ...
    #include "platforms/esp/32/drivers/_build.cpp.hpp"   // RMT, UART, SPI, I2S, LCD drivers
    ...
    
    FL_NO_UNWIND_END

    drivers/_build.cpp.hpp wraps the driver subdir includes a second time at lines 21+43 — belt-and-suspenders.

    Result: 3,007 FDEs survive in the wrapped .o

    $ xtensa-esp32s3-elf-readelf -S .pio/build/esp32s3/lib311/FastLED/fl/build/platforms+.cpp.o
      [8402] .eh_frame    PROGBITS  size 0x8890 = 34,960 bytes
      [8403] .rela.eh_frame ...
    
    $ xtensa-esp32s3-elf-readelf --debug-dump=frames platforms+.cpp.o | grep -c "FDE cie"
    3007
    

    GCC emitted 3,007 frame description entries — one per function in the unity TU — despite the FL_NO_UNWIND_BEGIN wrap covering every single function. The wrap is doing literally nothing.

    Side-by-side: wrapped vs unwrapped TUs

    TU FL_NO_UNWIND_BEGIN? .eh_frame in .o .eh_frame in firmware.bin
    platforms+.cpp.o YES (lines 8 + 21) 34,960 B 34,960 B
    fl.audio+.cpp.o NO 34,324 B 34,324 B
    fl.gfx+.cpp.o NO 17,184 B 17,184 B
    fl.channels+.cpp.o NO 15,448 B 15,448 B

    Wrapped and unwrapped TUs behave identically. Both ship full unwind tables. The _Pragma("GCC optimize(\"no-unwind-tables\")") form is a no-op for .eh_frame on this toolchain.

    Why the macro fails — root cause

    src/fl/stl/compiler_control.h:330:

    #define FL_NO_UNWIND_BEGIN _Pragma("GCC push_options") _Pragma("GCC optimize(\"no-unwind-tables\")")

    Two compounding problems:

    1. Wrong flag. GCC has two separate .eh_frame emitters:

    Flag Default on ESP32 Used for
    -funwind-tables OFF C++ exception unwind (we have -fno-exceptions, so it'd be off anyway)
    -fasynchronous-unwind-tables ON panic handler backtrace, gdb, profilers

    The actual emitter on ESP32 is -fasynchronous-unwind-tables, not -funwind-tables. Our pragma flips the wrong switch.

    2. The optimize attribute doesn't reliably propagate codegen flags. Per the GCC documentation for __attribute__((optimize(...))):

    "Not every optimization is controllable through this attribute. Generally, optimizations are turned on or off only via command-line options that are tested at parse time."

    -fno-asynchronous-unwind-tables is a codegen flag, not an -O*-style optimization flag. Even if we changed the pragma string to "no-asynchronous-unwind-tables", GCC may or may not honor it depending on the version. The 3,007 FDEs in the wrapped object file confirm GCC 14.2.0 / xtensa-esp-elf is silently no-op'ing the current pragma.

    The fix that actually works

    Pass the flags on the compile command line, not via pragma:

    -fno-asynchronous-unwind-tables
    -fno-unwind-tables
    

    For PlatformIO consumers this needs library-level injection. Two options:

    1. library.json — add a build.flags array for FastLED so every .cpp in lib*/FastLED/ gets these flags on the cc1 command line. Targeted, won't affect user sketches.

    2. platformio.ini template — surface a FASTLED_STRIP_EH_FRAME=1 shortcut that expands to the two compile flags via build_unflags + build_flags. User-controllable, opt-in.

    For our internal builds (bash compile ...) we'd add these to whatever defines flags for ESP32 release builds. Estimated savings: ~169 KB libFastLED.a eh_frame + ~56 KB libstdc++.a eh_frame if we can also propagate to the toolchain's libstdc++ link.

    Gating: leave eh_frame in for debug builds

    The existing FL_NO_UNWIND_ACTIVE resolution logic in compiler_control.h:285-313 already covers the right gating semantics:

    • FASTLED_FORCE_UNWIND_TABLES=1 → keep (e.g. when developing and need backtraces)
    • Debug-detected (!defined(NDEBUG), CONFIG_ESP_SYSTEM_PANIC_PRINT_BACKTRACE, etc.) → keep
    • Release build with no diagnostic indicators → strip

    Just swap the macro body from emitting a broken pragma to feeding the right value into a build-system include of the correct flags. The policy is correct; the mechanism is wrong.

  4. zackees commented on May 12, 2026

    @zackees
    MemberAuthor

    Cross-link: filed on fbuild as FastLED/fbuild#243

    The right fix for the 225 KB of orphan .eh_frame is centralized in the build system, not in FastLED headers. Filed FastLED/fbuild#243 — "ESP32: auto-strip .eh_frame when exception handling and panic backtrace are both off" — to track the proper implementation: parse sdkconfig panic mode + project build flags, inject -fno-asynchronous-unwind-tables -fno-unwind-tables on the compile command line when nothing in the build asks for unwind info.

    The FL_NO_UNWIND macros can stay as documentation of intent and as the user-visible FASTLED_FORCE_NO_UNWIND_TABLES / FASTLED_FORCE_UNWIND_TABLES policy knob, but the actual byte-stripping work moves to fbuild.

  5. zackees commented on May 12, 2026

    @zackees
    MemberAuthor

    Update on the cross-link: refined the proposal in FastLED/fbuild#243 with a per-architecture policy split.

    Xtensa (ESP32 / S2 / S3): the ESP-IDF panic backtrace walks register windows, not .eh_frame. Safe to strip unconditionally when -fno-exceptions is in effect. Dominant FastLED-on-ESP32 case lands here.

    RISC-V (C3 / C6 / H2 / C5 / P4): ESP-IDF panic backtrace defaults to frame-pointer walking. Strip by default; preserve only if user opts into DWARF unwinding via CONFIG_ESP_SYSTEM_USE_EH_FRAME=y (which is opt-in, not default).

    Result: stock ESP32-S3 Blink drops from 657 KB → ~432 KB out of the box with no diagnostic regression. Comment: FastLED/fbuild#243 (comment)

  6. zackees commented on May 12, 2026

    @zackees
    MemberAuthor

    Spawned follow-up #2474 to purge the FL_NO_UNWIND macros and FASTLED_FORCE_*_UNWIND_TABLES overrides from src/fl/stl/compiler_control.h and their two call sites in src/platforms/esp/32/_build.cpp.hpp + src/platforms/esp/32/drivers/_build.cpp.hpp. Zero source-level risk (the macros were no-ops). Migration path for any user who had -DFASTLED_FORCE_NO_UNWIND_TABLES=1 is the build_flags form documented in #2473 and src/fl/channels/README.md's new "Reducing Binary Size" section.

  7. zackees commented on May 12, 2026

    @zackees
    MemberAuthor

    Also filed against the starter project: FastLED/PlatformIO-Starter#6 — add the two -fno-*unwind-tables flags to every ESP32 (and Cortex-M / RISC-V) .ini in platforms/. Until fbuild#243 lands, this is the place where new FastLED users meet the flag, so the size win is opt-out instead of opt-in.

  8. added 2 commits that reference this issue on May 13, 2026
  9. zackees commented on Jun 5, 2026

    @zackees
    MemberAuthor

    Issue #2473 — -fno-unwind-tables is a no-op for firmware.bin on current master (xtensa-esp-elf-gcc 14.2.0)

    TL;DR

    The -fno-asynchronous-unwind-tables -fno-unwind-tables flags suggested in
    src/fl/channels/README.md ("Reducing Binary Size") do not reduce
    firmware.bin size on ESP32-S3 with the current toolchain
    , across both the
    PlatformIO (pioarduino IDF 5.4) and Arduino-CLI (esp32:esp32 3.1.1, IDF 5.3)
    toolchains.

    .eh_frame is already absent from both default builds — only .debug_frame
    (DWARF, non-loadable, lives in the ELF, not in the flash image) survives, and
    xtensa is not currently emitting any unwind data into a PT_LOAD segment.
    Stripping it via codegen flags rewrites the codegen (different bytes in
    .flash.text) but produces a firmware.bin of identical size.

    fbuild cannot be measured — it still hangs on cold ESP32-S3 builds
    (fbuild#117), even with warm PlatformIO caches sitting next to it.

    Setup

    Item Value
    Sketch examples/Blink/Blink.ino (single NEOPIXEL controller, pin 3)
    Board esp32-s3-devkitc-1 (PIO/fbuild), esp32:esp32:esp32s3,PartitionScheme=huge_app,FlashSize=4M,USBMode=default,CDCOnBoot=default,FlashMode=qio (Arduino-CLI)
    Branch master
    Commit 511730eb1c
    Toolchain (PIO/fbuild) xtensa-esp-elf-gcc 14.2.0 via pioarduino 54.03.20 (IDF 5.4)
    Toolchain (Arduino-CLI) esp32:esp32 3.1.1, also xtensa-esp-elf-gcc 14.2.0 (IDF 5.3)
    Host Windows 10, PowerShell + Bash, native (no Docker)

    Baseline = master ci/boards.py as-shipped. "No-unwind" = same ESP32_S3_DEVKITC_1
    with added build_flags = ["-fno-asynchronous-unwind-tables", "-fno-unwind-tables"].
    Arduino-CLI no-unwind = same flags injected via two --build-property overrides:

    --build-property "compiler.cpp.extra_flags=-fno-asynchronous-unwind-tables -fno-unwind-tables"
    --build-property "compiler.c.extra_flags=-fno-asynchronous-unwind-tables -fno-unwind-tables"
    

    Binary-size comparison

    Toolchain unwind tables firmware.bin firmware.elf Δ bin vs baseline Notes
    PlatformIO (pio run) on (master default) 673,504 B 38,885,828 B — baseline; cksum 3946972219
    PlatformIO (pio run) off (-fno-(asynchronous-)unwind-tables) 673,504 B 38,886,292 B ±0 B bytes differ (cksum 2437415167), size identical
    Arduino-CLI (arduino-cli compile) on (toolchain default) 687,152 B 41,008,324 B — baseline
    Arduino-CLI (arduino-cli compile) off (extra_flags) 687,152 B 41,009,180 B ±0 B bytes differ (cksum 134174001 → 1420100290), size identical
    fbuild (fbuild ... build) off — — — timed out at 30 min; fbuild#117

    firmware.elf deltas (+464 B for PIO, +856 B for Arduino) are entirely in
    DWARF debug sections (different .debug_frame content after re-compile); the
    flash image is byte-count identical.

    ELF section sizes (loadable only)

    PIO, no-unwind run (current master + flags)

    .flash.text             270,892
    .flash.rodata           322,844
    .iram0.text              64,727
    .iram0.text_end              37
    .iram0.vectors            1,027
    .dram0.data              13,584
    .dram0.bss               11,584
    .rtc.text                   256
    .rtc.force_fast              28
    .rtc_reserved                40
    

    No .eh_frame section. .debug_frame = 388,040 B (DWARF — not flashed).

    Arduino-CLI, baseline (no flags)

    .flash.text             252,546
    .flash.rodata           356,136
    .iram0.text              63,551
    .iram0.text_end             189
    .dram0.data              13,500
    .dram0.bss               10,912
    

    No .eh_frame section. .debug_frame = 427,628 B (DWARF — not flashed).

    Arduino-CLI, no-unwind (extra_flags injected)

    .flash.text             252,546   (same)
    .flash.rodata           356,136   (same)
    .iram0.text              63,551   (same)
    .iram0.text_end             189   (same)
    .dram0.data              13,500   (same)
    .dram0.bss               10,912   (same)
    

    Loadable sections byte-for-byte identical to baseline on Arduino-CLI —
    the only ELF delta is in DWARF.

    Why isn't the README's "~180 KB savings" reproducing?

    The README's "Reducing Binary Size" section (src/fl/channels/README.md:1058)
    notes:

    The compiler emits DWARF .eh_frame / FDE unwind tables by default on most
    toolchains. On ESP32-S3 release builds this can add ~180 KB even when
    -fno-exceptions is set.

    This audit could not reproduce that on master today:

    • xtensa-esp-elf-gcc 14.2.0 (both via PIO 54.03.20 and Arduino-CLI 3.1.1) does
      not emit .eh_frame for an ESP32-S3 Arduino build of Blink — only
      .debug_frame, which is a DWARF debug section that is never flashed.
    • The README's flags do change .flash.text codegen subtly (different bytes,
      same byte count on PIO; byte-for-byte identical loadable sections on
      Arduino-CLI), so they are applied — they just don't shrink anything.
    • The original "180 KB" measurement may have been against an older toolchain
      (the FL_NO_UNWIND removal predates the 14.2.0 update) or against
      firmware.elf rather than firmware.bin. The deltas in .debug_frame
      (388 KB on PIO, 428 KB on Arduino-CLI) are in the ELF but never reach flash.

    Drift from the original issue snapshot

    Issue #2473 measured on feat/remove-legacy-driver-registry-macro @ 4127a0c8da:
    firmware.bin = 657,072 B. Current master (511730e, PIO same toolchain):
    673,504 B. That's +16,432 B drift between the branch in the issue and
    today, in regular work — .flash.text +10,448 B, .flash.rodata +5,780 B,
    .iram0.text +200 B. This is normal feature accretion since the branch was
    cut, not unwind-related.

    Recommendation

    1. Remove or clarify the "Reducing Binary Size" guidance in
      src/fl/channels/README.md. With xtensa-esp-elf-gcc 14.2.0, the flags do
      nothing for firmware.bin. Users who add them expecting a 180 KB reduction
      will be disappointed.

    2. The 313 KB delta vs 3.10.3 lives somewhere else. Per the issue's own
      detailed breakdown, the largest reducible chunks today are:

      • Channel::showPixels 5 KB (single GRB instantiation pulling
        gamma/dither/brightness)
      • ChannelEngineRMTImpl::createChannel 4.6 KB + reconfigureForNetwork
        2.2 KB (full dynamic lifecycle pulled in for static addLeds)
      • RmtMemoryManager 4.5 KB (runtime memory-block planner)
      • printf-family ~36 KB (likely FL_LOG/FL_WARN ODR-using
        _vfprintf_r)

      These are codegen/feature changes, not codegen-flag tweaks.

    3. fbuild#117 still bites. fbuild ... build -e esp32s3 hangs at the
      post-toolchain-fetch stage and times out at 30 min even with PIO caches
      already populated. Any size-measurement workflow on ESP32-S3 has to go
      through pio run or arduino-cli compile today.

    Reproduction

    # Baseline (master as-shipped)
    bash compile esp32s3 --examples Blink --platformio
    stat .build/pio/esp32s3/.pio/build/esp32s3/firmware.bin
    
    # No-unwind variant: patch ci/boards.py ESP32_S3_DEVKITC_1 with
    #   build_flags=["-fno-asynchronous-unwind-tables", "-fno-unwind-tables"]
    # then rebuild — the cflag fingerprint forces FastLED + framework-arduino
    # recompile (~2 min vs 19 min cold).
    bash compile esp32s3 --examples Blink --platformio
    stat .build/pio/esp32s3/.pio/build/esp32s3/firmware.bin
    
    # Arduino-CLI baseline + no-unwind:
    arduino-cli compile -b "esp32:esp32:esp32s3:PartitionScheme=huge_app,FlashSize=4M,USBMode=default,CDCOnBoot=default,FlashMode=qio" \
      --library "$REPO" --build-path "$REPO/.build/arduino-cli/esp32s3-baseline" "$REPO/examples/Blink"
    arduino-cli compile -b "esp32:esp32:esp32s3:PartitionScheme=huge_app,FlashSize=4M,USBMode=default,CDCOnBoot=default,FlashMode=qio" \
      --library "$REPO" \
      --build-property "compiler.cpp.extra_flags=-fno-asynchronous-unwind-tables -fno-unwind-tables" \
      --build-property "compiler.c.extra_flags=-fno-asynchronous-unwind-tables -fno-unwind-tables" \
      --build-path "$REPO/.build/arduino-cli/esp32s3-nounwind" "$REPO/examples/Blink"
    
    # fbuild — currently hangs (fbuild#117)
    bash compile esp32s3 --examples Blink --fbuild   # timed out at 30 min in this audit
  10. zackees commented on Jun 5, 2026

    @zackees
    MemberAuthor

    Issue #2473 — Comprehensive symbol/section analysis: where the 673 KB lives

    TL;DR

    A fresh symbol-level audit of the current master (511730e) ESP32-S3 Blink
    build (PlatformIO, IDF 5.4, xtensa-esp-elf-gcc 14.2.0, firmware.bin = 673,504 B)
    identifies five concrete tree-shake failures that account for ~150 KB of
    bloat
    the user can't avoid by writing a smaller sketch:

    # Tree-shake leak Size Mechanism
    1 mbedtls/x509_crt_bundle (Mozilla CA cert bundle) 68,000 B Arduino-core auto-links libwpa_supplicant.a, which references esp_crt_bundle_attach → drags in the full root CA blob. Pure ESP-IDF/Arduino problem (not FastLED), but it's the biggest single contributor to the 313 KB delta vs 3.10.3.
    2 SD / FS / _svfprintf_r chain ~14,000 B src/fl/system/file_system.cpp.hpp includes platforms/fs_sdcard_arduino.hpp whenever <SD.h> exists. That #include <SD.h> triggers PlatformIO LDF to link libSD.a + libFS.a + Arduino::VFSImpl, which calls C snprintf → pulls _svfprintf_r (11 KB) for a sketch that never opens a file.
    3 Mesh networking strings ~17,000 B Arduino-core's libmesh.a (mesh_parent, mesh_schedule, mesh_utilities, mesh_route, mesh.o, mesh_main, mesh_network) is always linked. Pure Arduino-ESP32 problem; not FastLED.
    4 Channel::showPixels 5.7 KB monolith ~5,700 B One function pulls ScaledPixelIteratorBrightness, ScaledPixelIteratorRGB, ScaledPixelIteratorRGBW, Gamma8::getOrCreate, XYMap::*, Rgbww variant code into every NEOPIXEL Blink, even when setBrightness/setGamma/setCorrection are never called. No tiered fast-path.
    5 ChannelEngineRMTImpl::createChannel 4.6 KB ~4,600 B Static FastLED.addLeds<> pulls in the dynamic lifecycle: reconfigureForNetwork, NetworkDetector::isAnyNetworkActive, hot-plug add/remove paths, and an sstream-based warning emitter.
    EspIO singleton instantiates both UART + USB-Serial-JTAG ~1,000 B EspIO holds mUart AND mUsbSerialJtag as members; the if (mUseUsbSerialJtag) is a runtime check, so the linker can't dead-strip either driver. Not the biggest leak by bytes, but it's the cleanest example of a fixable polymorphism failure.

    These five (plus the EspIO oddity) compose about 105 KB of structural bloat
    that any user of the default Channel API has to pay
    . The rest of the binary —
    ~568 KB — is broadly load-bearing (the RMT driver, FastLED's Channel API, the
    Arduino HardwareSerial console, ESP-IDF init/RTOS/heap, libc).

    The full breakdown follows.

    1. Section-level top-down (xtensa-esp32s3-elf-size -A)

    Section Bytes KB Loaded?
    .flash.text 270,892 264.5 ✅ flashed
    .flash.rodata 322,844 315.3 ✅ flashed
    .iram0.text 64,727 63.2 ✅ IRAM
    .iram0.vectors 1,027 1.0 ✅ IRAM
    .dram0.data 13,584 13.3 ✅ DRAM
    .dram0.bss 11,584 11.3 (zeroed)
    .rtc.* 324 0.3 ✅ RTC
    .debug_* 36,728,756 35,867 ❌ ELF only

    firmware.bin = 673,504 B. Loadable total (.flash.text + .flash.rodata +
    .iram0.text + .iram0.vectors + .dram0.data + .rtc.*) ≈ 685 KB; bin is
    slightly smaller because boot stubs are not duplicated and some sections
    overlap in the image layout.

    2. Subsystem breakdown of .flash.text + .iram0.text (~358 KB sized symbols, 4012 entries)

    Subsystem Bytes KB Symbols vs #2473 snapshot
    fl::* (FastLED) 88,286 86.2 1024 +18 KB (was 70 KB)
    ESP-IDF (rmt, gdma, tlsf, mmu, nvs, panic, intr, hal, mbedtls glue) 98,720 96.4 909 +40 KB (was 56 KB)
    libc (printf-family + dtoa + ieee754 + locale + mem*/str*) ~53,000 ~51.7 ~40 ≈ same (was 56 KB)
    Arduino core (HardwareSerial, VFS, IPAddress, MAC/SHA/MD5, init) 29,883 29.2 215 +5 KB
    FreeRTOS 16,991 16.6 93 +5 KB
    App (setup/loop/printBeforeSetupInfo) 1,166 1.1 3 ≈ same

    Total bin grew 16 KB vs the issue's snapshot (657 KB → 673 KB), but FastLED
    grew 18 KB and ESP-IDF grew 40 KB — net partially offset by some
    already-shrunk areas.

    2.1 FastLED 88 KB — what's inside

    FastLED subsystem Bytes KB vs #2473
    RMT (engine + encoder + memory mgr + buffer pool) 27,550 26.9 -0.6 KB
    OTHER fl::* (Singleton, EngineEvents, Lifecycle, misc) 15,733 15.4 +8.3 KB
    Channels (Channel::*, ChipsetTiming, ChannelData) 11,780 11.5 -1.8
    PixelIterator / PixelController 10,227 10.0 +5.9 KB
    ChannelManager 5,347 5.2 +1.4
    shared_ptr / weak_ptr / RefCount 3,813 3.7 +3.2 KB
    fl::basic_string 3,227 3.2 +0.4
    EngineEvents / Lifecycle / Singleton 2,423 2.4 +1.1
    fl::vector_basic / vector_psram 2,205 2.2 -0.3
    fl::task::Scheduler 1,936 1.9 ≈ same
    CFastLED / CLEDController / CPixelLEDController 1,807 1.8 new (was bucketed)
    Rgb2Rgbw / rgb_2_rgbw_colorimetric 1,726 1.7 new
    Gamma LUT (ProgmemLUT16 + accessors) 512 0.5 -1.6

    The 18 KB FastLED growth concentrates in PixelIterator/Controller (+5.9),
    Other fl:: lifecycle/singleton glue (+8.3), and shared_ptr machinery
    (+3.2).

    2.2 Top 12 single largest FastLED symbols

    Bytes Symbol
    5,690 fl::Channel::showPixels(PixelController<GRB, 1, 0xFFFFFFFF>&)
    4,590 fl::ChannelEngineRMTImpl::createChannel(...)
    2,708 fl::RmtMemoryManager::allocateTx(uint8_t, bool, bool)
    2,160 fl::ChannelEngineRMTImpl::reconfigureForNetwork()
    1,930 fl::ChannelManager::addDriver(int, fl::shared_ptr<fl::IChannelDriver>)
    1,528 fl::detail::Rmt5EncoderImpl::initialize(ChipsetTiming, unsigned long)
    1,151 fl::basic_string::write(const char*, unsigned)
    948 fl::ChannelEngineRMTImpl::processPendingChannels()
    826 fl::RmtMemoryManager::calculateMemoryBlocks(bool)
    738 fl::ChannelEngineRMTImpl::configureChannel(...)
    676 fl::ChannelManager::selectDriverForChannel(...)
    606 fl::detail::Rmt5PeripheralESPImpl::waitAllDone(void*, unsigned long)

    The shape matches the issue's earlier snapshot — same hotspots, all slightly
    larger on master.

    2.3 Top non-FastLED single symbols

    Bytes Symbol Source
    11,309 _vfprintf_r newlib (FILE* float path)
    11,118 _svfprintf_r newlib (string float path)
    7,337 _svfiprintf_r newlib (string integer path)
    7,265 _vfiprintf_r newlib (FILE* integer path)
    4,192 port_IntStack FreeRTOS
    3,219 _dtoa_r newlib (float → string)
    2,723 __ieee754_pow libm

    _vfprintf_r and _svfprintf_r are both linked because BOTH fprintf and
    snprintf get used (fprintf from libesp_driver_gpio, snprintf from
    platforms+.cpp.o's OTA code — see §4.2). Newlib also pulls in the
    integer-only fallbacks. ~37 KB total from the printf family alone.

    3. .flash.rodata 322 KB — the elephant

    .flash.rodata is larger than .flash.text but is rarely audited because
    most data is anonymous string literals / tables that don't surface as nm
    symbols. Reconstructed from the map file's section assignments, the biggest
    single contributors are:

    Bytes KB Source Notes
    69,880 68.2 libmbedtls.a(x509_crt_bundle.S.obj) .rodata.embedded Mozilla CA root bundle — pulled in by libwpa_supplicant.a(esp_eap_client.c.obj)'s reference to esp_crt_bundle_attach. Arduino-ESP32 auto-links WPA Supplicant even when the sketch never touches WiFi. This is the single biggest fixable line item.
    57,902 56.5 src/main.cpp.o .str1.1 (merged string pool) Aggregate of all FL_WARN/FL_LOG/format string literals that get inlined into the sketch TU from FastLED headers. Map file attributes the merged region to the first symbol that contributed (ClocklessIdf5 ctor here) — actually the union of all inlined log strings.
    11,108 10.8 libmesh.a(mesh_parent.o) ESP-IDF mesh networking strings — always linked by Arduino.
    8,484 8.3 libFastLED.a(third_party+.cpp.o) fl::third_party::huffTable Huffman decode table — audio codec data linked into a Blink build.
    7,668 7.5 libc.a(libc_a-svfwprintf.o) wide-char printf rodata
    7,315 7.1 libc.a(libc_a-svfscanf.o) scanf rodata
    6,133 6.0 libc.a(libc_a-svfiscanf.o) integer scanf rodata
    6,053 5.9 libmbedtls_2.a(ssl_tls12_server.c.obj) TLS 1.2 server strings — never used by FastLED but linked because mbedtls is monolithic.
    6,006 5.9 libesp_common.a(esp_err_to_name.c.obj) .str1.1 ESP-IDF error-code → human-name strings
    5,799 5.7 libFastLED.a(platforms+.cpp.o) otaHttpGetHandler.str1.1 OTA HTTP server response strings — OTA functions are unreachable but their string pool survives in the merged pool.
    5,146 5.0 libmesh.a(mesh_schedule.o) More mesh strings
    4,436 4.3 libmbedtls_2.a(ssl_ciphersuites.c.obj) Cipher-suite names
    3,983 3.9 libc.a(libc_a-strtod.o) strtod tables
    3,553 3.5 libmesh.a(mesh_utilities.o)
    3,398 3.3 libc.a(libc_a-strerror.o) errno → string table
    3,335 3.3 libmesh.a(mesh_route.o)
    3,073 3.0 libmbedcrypto.a(oid.c.obj) OID string table
    2,782 2.7 libc.a(libc_a-strftime.o) strftime locale tables
    2,723 2.7 libmesh.a(mesh.o)
    2,532 2.5 libbtdm_app.a(ip_funcs.o) Bluetooth+IP coex strings
    2,499 2.4 libm.a(libm_a-ef_pow.o) pow() coefficient table
    2,048 2.0 libFastLED.a(third_party+.cpp.o) PLM_AUDIO_SYNTHESIS_WINDOW PL_MPEG audio synthesis lookup table — audio codec data again.
    1,952 1.9 libmbedtls_2.a(ssl_ciphersuites.c.obj) ciphersuite_definitions
    1,800 1.8 libesp_common.a(esp_err_to_name.c.obj) esp_err_msg_table
    1,810 1.8 libhttp_parser.a HTTP parser strings

    Top-10 rodata contributors sum: ~187 KB / 322 KB rodata = 58% of all
    rodata.
    Of that:

    • ~98 KB is ESP-IDF / Arduino auto-linked WiFi/TLS/Mesh code that the sketch never uses
    • ~57 KB is FastLED's merged inline-log format-string pool
    • ~10 KB is FastLED's third_party/ audio/codec lookup tables that survive in the link
    • ~28 KB is libc stdio rodata

    4. Tree-shake failure walkthroughs

    4.1 SD / FS / _svfprintf_r (~14 KB)

    src/fl/system/file_system.cpp.hpp:20 conditionally includes
    platforms/fs_sdcard_arduino.hpp based on header presence:

    #elif FL_HAS_INCLUDE(<SD.h>) && FL_HAS_INCLUDE(<fs.h>)
    #include "platforms/fs_sdcard_arduino.hpp"
    #define FASTLED_HAS_SDCARD 1

    fs_sdcard_arduino.hpp:6,14 unconditionally:

    #include <SPI.h>
    #include <SD.h>     // <- triggers PlatformIO LDF to pull libSD.a

    PlatformIO's Library Dependency Finder sees <SD.h> in a FastLED header,
    pulls libSD.a, which pulls libFS.a (VFSImpl::open, VFSFileImpl::*).
    VFSFileImpl::VFSFileImpl calls C snprintf for path normalization, which
    makes the linker extract libc_a-snprintf.o, which references _svfprintf_r
    (11,118 B) and _dtoa_r. Result: ~14 KB of file-system + printf bloat in
    every ESP32 Blink build.

    Fix surface: gate make_sdcard_filesystem (and the <SD.h> include) behind
    an opt-in like FASTLED_USE_SDCARD, or replace the FL_HAS_INCLUDE heuristic
    with an explicit user setting. The file-system header probe is too eager — it
    opts in by default any time the Arduino SD library is even present.

    4.2 mbedtls X.509 cert bundle (68 KB)

    Map-file trace:

    libmbedtls.a(x509_crt_bundle.S.obj) .rodata.embedded                69,880 B
                                  libmbedtls.a(esp_crt_bundle.c.obj)  (_binary_x509_crt_bundle_start)
                                  libwpa_supplicant.a(esp_eap_client.c.obj) (esp_crt_bundle_attach)
    

    ESP-IDF's WPA Supplicant calls esp_crt_bundle_attach from
    esp_eap_client.c.obj, which the linker resolves by extracting
    esp_crt_bundle.c.obj, which pulls in the 68 KB embedded cert bundle.
    Arduino-ESP32 auto-links the entire WiFi+WPA stack even for sketches that
    don't call WiFi.begin().
    This is upstream of FastLED — the only mitigation
    inside FastLED is documentation ("ESP32-S3 Arduino baseline carries 68 KB of
    CA certs you can't remove without recompiling Arduino-core with WPA
    Supplicant stripped"), or pushing for an Arduino-core fix that elides
    WPA/cert-bundle unless WiFi is initialized.

    4.3 ESP-IDF mesh strings (~17 KB)

    Same root cause as 4.2 — Arduino-ESP32 auto-links the WiFi/mesh
    infrastructure. Not FastLED's fault; can only be tracked, not fixed inside
    this repo.

    4.4 EspIO always instantiates both UART + USB-Serial-JTAG (~1 KB)

    src/platforms/esp/32/detail/io_esp_jtag_or_uart.hpp:51-93:

    class EspIO {
    public:
        void print(const char* str) FL_NOEXCEPT {
            reportInitDiagnosticsIfNeeded();
            if (mUseUsbSerialJtag) {        // <-- runtime branch
                mUsbSerialJtag.write(str);
            } else {
                mUart.write(str);
            }
        }
    private:
        UartEsp32         mUart;            // <-- both drivers always
        UsbSerialJtagEsp32 mUsbSerialJtag;  //     constructed
        bool mUseUsbSerialJtag;
    };

    Both mUart and mUsbSerialJtag are non-static, non-template members of the
    single EspIO singleton. Every code path through print()/println()/
    read()/flush() has a if (mUseUsbSerialJtag) runtime test, so the linker
    sees both drivers as reachable from the same EspIO symbol and can't
    dead-strip either one. ~422 B (UartEsp32 ctor) + ~462 B (UsbSerialJtag) +
    ~274 B (reportInitDiagnosticsIfNeeded itself) of always-linked overhead.

    Fix surface: replace the boolean branch with a fl::variant<UartEsp32, UsbSerialJtagEsp32> or a polymorphic unique_ptr<IEspSerial> chosen once at
    construction. Then only the selected driver's text section is reachable.

    4.5 Channel::showPixels 5.7 KB — no tiered fast path

    Disassembly of the live fl::Channel::showPixels<GRB, 1, 0xFFFFFFFF> calls
    (among others):

    • fl::detail::ScaledPixelIteratorBrightness::advance (brightness scaling — even when setBrightness was never called)
    • fl::detail::ScaledPixelIteratorRGB::advance / ::operator!= (RGB scaling iterator)
    • fl::detail::ScaledPixelIteratorRGBW::advance / ::operator!= (RGBW scaling iterator — even though Blink is plain GRB)
    • fl::Gamma8::getOrCreate(float) (gamma table lookup)
    • fl::XYMap::getHeight() / ::getWidth() / ::mapToIndex (2D coordinate mapping — even for a single linear strip)
    • fl::ChannelManager::findDriverByName / selectDriverForChannel
    • fl::PixelIteratorAny::init / ~PixelIteratorAny (type-erased iterator wrapper)
    • fl::makeScaledPixelRangeRGB(fl::PixelIterator*) (scaled range builder)
    • __cxa_guard_acquire/release (thread-safe local static init)
    • _Unwind_Resume (C++ exception unwind — emitted by destructor cleanup paths even with -fno-exceptions)

    The fast path through this function for a one-controller, no-brightness,
    no-gamma, no-XYMap, no-RGBW Blink should be ~500 B (advance source iterator,
    copy bytes, hand to RMT). Instead the whole 5.7 KB carries every optional
    codepath.

    Fix surface: split showPixels into specialized templates and pick the
    narrowest one at addLeds<> instantiation. The compiler/linker can then
    dead-strip the unused variants per controller-type.

    4.6 ChannelEngineRMTImpl::createChannel 4.6 KB pulls dynamic lifecycle

    Live call targets from createChannel:

    • fl::NetworkDetector::isAnyNetworkActive (WiFi coexistence check — even for sketches that never call WiFi.begin())
    • fl::RmtMemoryManager::{instance, allocateTx, allocateDMA, freeDMA, calculateMemoryBlocks, availableTxWords, hasActiveRxChannels, isDMAAvailable, recordRecoveryAllocation, free} — full memory planner reachable from one entry point
    • fl::sstream::appendFormatted(long) / appendFormatted(unsigned long) — for warning messages
    • fl::println (which feeds into the EspIO singleton)
    • _Unwind_Resume — exception cleanup

    reconfigureForNetwork (2.2 KB) handles hot-plug add/remove of channels when
    the network state changes. A sketch that calls addLeds<> exactly once at
    static-init time never reconfigures, so this code path is dead weight.

    Fix surface: split a "static-only" channel construction path from the
    dynamic-reconfigure path, and only instantiate the dynamic one when the user
    actually calls removeLeds() or hot-adds a channel.

    4.7 FastLED third_party/ audio data leaking into Blink

    fl::third_party::huffTable (8,484 B) and
    fl::third_party::PLM_AUDIO_SYNTHESIS_WINDOW (2,048 B) — totalling 10.5 KB
    of MPEG-Audio decode tables
    — are linked into the Blink binary. Source is
    src/fl/build/third_party+.cpp aggregate. The audio decoder functions
    themselves are dead-stripped, but their .rodata.const tables survive because
    they have external linkage and are at the namespace-scope .rodata section,
    which the linker preserves whenever any symbol from
    libFastLED.a(third_party+.cpp.o) is live (it appears huffTable and the
    window are addressed in non-tree-shakable references).

    Fix surface: move the audio tables under an #ifdef FASTLED_HAS_CODEC guard,
    or split third_party+.cpp into one TU per third-party codec so the linker
    can drop unused TUs entirely.

    5. Other observations

    • __gxx_personality_v0 (717 B) and _Unwind_Resume callsites are
      present despite -fno-exceptions. GCC still emits cleanup code that
      references the unwind ABI when destructors are involved on non-trivially-
      destructible types in stack frames. With the FL_NO_UNWIND macros now
      removed (audit ESP32-S3 binary size: 657 KB on master vs 344 KB on 3.10.3 — remaining +313 KB delta breakdown #2473 above), the only remaining mitigation is at the global
      -fno-exceptions -fno-rtti level (already set).
    • The port_IntStack 4 KB is the FreeRTOS interrupt-handler stack. Pre-
      allocated, can't shrink without reconfiguring CONFIG_FREERTOS_ISR_STACKSIZE.
    • 2x same-address duplicate constructors / destructors in the nm output are
      GCC's C1/C2 (complete/base) constructor variants pointing at the same
      generated body — not a real duplication.

    6. Recommended priority order for fixes (FastLED-internal)

    1. (High value, low risk) Gate the <SD.h> include in
      fs_sdcard_arduino.hpp behind an opt-in macro
      (FASTLED_USE_SDCARD). Saves ~14 KB for the 99% of sketches that
      never touch SD.

    2. (High value, medium risk) Split Channel::showPixels into
      specialized templates for the (no-brightness, no-gamma, no-XYMap, RGB-only)
      common case. Estimated ~3 KB savings on the default path.

    3. (High value, medium risk) Move audio/codec lookup tables in
      src/fl/third_party/ under explicit codec opt-in macros, or split into
      per-codec TUs. Saves ~10.5 KB.

    4. (Medium value, medium risk) Replace EspIO's pair-of-members with a
      fl::variant or polymorphic selection so only one driver is linked. Saves
      ~1 KB.

    5. (Medium value, medium risk) Split ChannelEngineRMTImpl::createChannel
      into "static one-shot" and "dynamic reconfigure" paths. Saves
      ~2-3 KB for static addLeds<> users.

    6. (Documentation) Add a note in the size-tuning docs that ~85 KB of the
      ESP32-S3 baseline (mbedtls cert bundle 68 KB + libmesh 17 KB) is
      Arduino-ESP32's auto-linked WPA/WiFi/mesh stack, not FastLED, and cannot
      be removed without recompiling Arduino-core.

    Implementing 1-5 saves ~30 KB off the current 673 KB → ~643 KB.
    Combined with an Arduino-core fix to elide WPA+mesh when WiFi isn't used,
    the realistic ESP32-S3 NEOPIXEL Blink floor could approach ~555 KB
    (still 211 KB above 3.10.3, with the structural ChannelManager/RMT lifecycle
    being most of the residual).

    Reproduction

    # Build (current master, no flag changes)
    bash compile esp32s3 --examples Blink --platformio
    
    # Section breakdown
    ELF=.build/pio/esp32s3/.pio/build/esp32s3/firmware.elf
    xtensa-esp32s3-elf-size -A "$ELF"
    
    # Top symbols
    xtensa-esp32s3-elf-nm --print-size --size-sort --reverse-sort -C "$ELF" | head -40
    
    # Map-file rodata attribution (top contributors)
    MAP=.build/pio/esp32s3/.pio/build/esp32s3/firmware.map
    awk '/^ \.rodata/ {section=$0; getline; \
         if (NF>=3) { size=strtonum($2); src=$3; \
                     if (size>=500) print size "\t" section "\t" src}}' "$MAP" \
      | sort -nr | head -30
    
    # Tree-shake trace example: who pulls _svfprintf_r
    grep -B1 -A1 "(_svfprintf_r)$" "$MAP"
    # (_svfprintf_r) comes from libc_a-snprintf.o, which comes from
    # .pio/build/esp32s3/lib311/libFastLED.a(platforms+.cpp.o) (snprintf)
  11. zackees commented on Jun 5, 2026

    @zackees
    MemberAuthor

    Closing as superseded by #2773, which is the actionable tracker for ESP32-S3 size-reduction work (with corrected numbers — this issue's breakdown was used as the source per #2773's body). All remaining size-reduction sub-items live there. The analytical content here remains valuable as historical context.

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