Skip to content

Meta: ESP32-S3 NEOPIXEL Blink bloat reduction — staged plan to drop 388 KB → ≤ 280 KB (no API changes) #2885

Closed as not planned

Description

@zackees

Goal

Take ESP32-S3 NEOPIXEL Blink from 388,380 B flash today down to ≤ 280,000 B (-28 %) via knob flips, default changes, and dead-code suppression. No public API changes. All work lands on feat/esp32s3-bloat-reduction.

Reproduce the snapshot in this issue at any time:

bash compile esp32s3 --examples Blink --platformio
bash bloat esp32s3 --top 25

(See agents/docs/binary-size-analysis.md for the wrapper docs.)

First-pass snapshot — where the bytes are today

firmware.bin = 388,380 B flash + 37,460 B RAM, across 3,685 sized flash symbols.

Top archives (flash)

Bytes % Archive
87,271 22.5 % libFastLED.a
60,254 15.5 % (sketch) main.cpp.o
54,458 14.0 % libc.a (newlib printf engine)
18,198 4.7 % libesp_hw_support.a
15,743 4.1 % libFrameworkArduino.a
14,091 3.6 % libfreertos.a
13,886 3.6 % libhal.a
13,387 3.4 % libesp_driver_uart.a
11,842 3.1 % libesp_system.a
11,348 2.9 % libspi_flash.a
8,193 2.1 % libespcoredump.a
7,377 1.9 % libnvs_flash.a
... ... (53 other archives, all < 1.5 % each)

Top symbols (flash)

# Bytes Archive Symbol
1 58,770 (sketch) main.cpp.o fl::ClocklessIdf5<3, WS2812_800KHZ, GRB, 0, false, 280>::ClocklessIdf5() — the NEOPIXEL chipset ctor's FL_WARN/FL_LOG string pool (map-derived attribution).
2 11,309 libc.a _vfprintf_r (newlib)
3 11,118 libc.a _svfprintf_r
4 7,337 libc.a _svfiprintf_r
5 7,265 libc.a _vfiprintf_r
6 4,924 libc.a get_arg$isra$0 (×4 instances; printf arg-parsing helper, duplicated per TU)
7 4,761 libFastLED.a fl::Channel::showPixels<NEOPIXEL>
8 3,219 libc.a _dtoa_r
9 2,723 libm.a __ieee754_pow
10 2,363 libFastLED.a fl::ChannelEngineRMTImpl::createChannel
11 2,283 libFrameworkArduino.a uartBegin
12 2,252 libFastLED.a fl::ChannelEngineRMTImpl::reconfigureForNetwork()
13 2,252 libesp_driver_rmt.a rmt_new_tx_channel
14 2,054 libesp_driver_uart.a uart_rx_intr_handler_default
15 2,002 libFastLED.a fl::ChannelManager::addDriver
16 1,972 libFastLED.a fl::RmtMemoryManager::handleAllocateTxFailure
17 1,953 libesp_hw_support.a rtc_init
18 1,835 libespcoredump.a esp_core_dump_do_write_elf_pass
19 1,604 libespressif__esp_diagnostics.a diag_log_add
20 1,572 libFastLED.a fl::detail::Rmt5EncoderImpl::initialize
21 1,464 libFrameworkArduino.a printBeforeSetupInfo()
22 1,271 libheap.a tlsf_memalign_offs
23 1,177 libFastLED.a fl::Channel::resolveDynamicDriver()
24 1,151 libFastLED.a fl::basic_string::write
25 1,103 libespcoredump.a esp_core_dump_get_task_regs_dump

Section distribution

Bytes Section
269,546 .flash.text (code)
59,738 .iram0.text (hot code in IRAM)
59,096 .flash.rodata (read-only data — mostly FL_WARN strings)

Multi-stage strategy (no API changes)

Each stage lands as its own PR onto feat/esp32s3-bloat-reduction. Stages 0-2 are pure FastLED-repo changes. Stages 3-4 are PIO-config and documentation. Order is by risk (lowest first), not by impact — see the projected savings column.

Stage 0 — Docs-only: "Slim ESP32-S3 build" tutorial (~0 KB, blocker-free)

Add docs/SLIM_ESP32S3.md showing the exact platformio.ini build_flags users can paste in to recover the bytes that don't need code changes. Documents the existing levers below in one place so users can see the full set rather than discovering them piecemeal.

This stage ships zero behavioural change but unblocks every downstream stage by giving us a single document to point at when reviewers ask "does this stage break anything for users who already opted in to X?".

Acceptance: docs/SLIM_ESP32S3.md exists and lists every define + sdkconfig override below with measured savings.

Stage 1 — FASTLED_LOG_VERBOSITY=0 becomes default on Arduino-release builds (~58 KB)

#2791 already shipped the verbosity knob with three levels: 0 (release), 1 (default; current behaviour), 2 (verbose). The current default is 1 even though the use case for a debug-level default is essentially "FastLED maintainer running an example with Serial.print plumbing".

Change: in src/fl/log.h (or wherever FASTLED_LOG_VERBOSITY defaults), set the default to 0 unless NDEBUG is undefined AND a debug-toolchain marker is present. Arduino-IDE / PIO release builds set NDEBUG. Users who want logs back say -DFASTLED_LOG_VERBOSITY=1 in build flags or #define FASTLED_LOG_VERBOSITY 1 before #include <FastLED.h>.

Why this is a default flip, not an API change: the macro and its three levels were public API in #2791. We're only changing what unset defaults to. The FL_WARN(...) / FL_LOG(...) call surface is unchanged.

Risk: users relying on FastLED-emitted serial chatter for diagnostics would silently lose it. Mitigations:

  • Release-notes call-out + docs/SLIM_ESP32S3.md entry.
  • A loud one-time FL_FORCE_LOG("FastLED: log verbosity defaulted to 0; #define FASTLED_LOG_VERBOSITY 1 to restore") at first CFastLED::show() for one release cycle, then remove.

Projected savings: -58,770 B on the NEOPIXEL ctor's string pool, plus partial collapses on fl::Channel::showPixels (~1-2 KB) and fl::ChannelEngineRMTImpl::reconfigureForNetwork() (~500 B) once the FL_WARN literals get dead-stripped. Conservative estimate: -55 KB.

Verification:

bash bloat esp32s3 --build --no-summary
diff <(jq '.total_flash' .build/symbols/esp32s3/report.json) \
     <(jq '.total_flash' /tmp/baseline-report.json)
# Should drop ~55,000 B.

Stage 2 — Arduino-ESP32 boot-banner suppression (~3-4 KB)

printBeforeSetupInfo() (1,464 B in libFrameworkArduino.a/chip-debug-report.cpp.o) is the Arduino-ESP32 boot banner. It prints chip ID, flash size, SDK version, etc. to UART0 once at boot. For LED-only sketches this is dead bytes.

Two cleanly-scoped suppression paths:

  1. build_unflags = -DARDUHAL_LOG_LEVEL_* + build_flags = -DARDUHAL_LOG_LEVEL=0 — Arduino-ESP32's own knob. Already partially zero in PIO but the banner runs even at level 0. Need to verify the right combination.
  2. -DCONFIG_ARDUINO_ISR_IRAM=0 + -DARDUINO_LOOP_STACK_SIZE=4096 — adjacent knobs that nudge core-debug-report into the dead-strip set.

A FastLED-controlled FASTLED_SUPPRESS_ARDUINO_BOOT_BANNER define would forward to the right combination. No FastLED public API change.

Projected savings: -1,464 B (printBeforeSetupInfo()) + ~1-2 KB of adjacent chip-debug-report.cpp.o rodata strings = ~3 KB.

Stage 3 — sdkconfig.defaults overlay for FastLED-using projects (~10-15 KB)

Add tools/sdkconfig_for_smallest_fastled.defaults documenting the IDF kconfig flips users can apply via PIO's board_build.sdkconfig_defaults. Initial set:

Knob Disables Savings
CONFIG_ESP_COREDUMP_ENABLE_TO_FLASH=n libespcoredump (esp_core_dump_do_write_elf_pass, esp_core_dump_get_task_regs_dump) ~6-8 KB
CONFIG_BT_ENABLED=n Bluetooth stack init (usually already off for LED sketches; verify) ~0-15 KB
CONFIG_LOG_DEFAULT_LEVEL=ESP_LOG_NONE ESP-IDF log strings + diag_log_add ~2-3 KB
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y Bootloader chatter ~1 KB
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y Panic-formatter strings (vs. PRINT_REBOOT default) ~1-2 KB

These are user-side overrides; FastLED ships the file as documentation + a recommended copy-paste, not as the global default (we can't change ESP-IDF defaults from a library).

Projected savings: ~10-15 KB when all knobs applied. The numbers are bounded on the optimistic side since some archives already partially dead-strip without the explicit knob.

Stage 4 — FastLED-side cold-helper splits for the remaining hot paths (~3-5 KB)

The post-#2773 remediation work already cold-split Channel::showPixels (#2830), createChannel recovery (#2838), allocateTx fail path (#2840), and added the static-allocation opt-in (#2846). But the top-10 still shows these symbols at 4.7 KB / 2.3 KB / 2.0 KB respectively. Audit pass:

  1. fl::Channel::showPixels<NEOPIXEL> — 4,761 B. Most of this is the per-chipset if-constexpr fast-path code already split out in feat(stl): FL_NO_INLINE portable macro + cold-helper split for showPixels (#2773 item 2.1) #2830. Confirm that all FL_WARN sites inside the hot loop are guarded by FASTLED_LOG_VERBOSITY (Stage 1) so the second-order shrink from Stage 1 actually flows through.
  2. fl::ChannelEngineRMTImpl::reconfigureForNetwork — 2,252 B. Already cold-split by perf(rmt5): cold-helper split for createChannel recovery loop (#2773 item 2.2) #2838 but still 2.2 KB. Audit whether any of the remaining bytes are FL_WARN string-pool that Stage 1 will collapse.
  3. fl::ChannelManager::addDriver — 2,002 B. Confirm FL_NO_INLINE is set on its diagnostic emission helpers.
  4. fl::RmtMemoryManager::handleAllocateTxFailure — 1,972 B. Already split by perf(rmt5): split allocateTx fail-path into cold helper (#2773 item 2.5) #2840 with FL_NO_INLINE; verify the cold helper's FL_WARN strings get collapsed by Stage 1.

Projected savings: ~3-5 KB beyond what Stage 1 already recovers.

Stage 5 — fl::basic_string::write simplification (~0.5-1 KB)

fl::basic_string::write at 1,151 B is the formatted-string write path. Audit whether it pulls in float / wide-char machinery it doesn't need on embedded targets. Specifically:

  1. Inspect whether fl::basic_string::write(char*, unsigned int) is the right entry point, or whether write(const char*, unsigned int) could be the only export with write(char*, ...) redirecting to it via inline.
  2. Whether the fl::sstream writer can skip the locale machinery std::ostream brings in.

Projected savings: ~0.5-1 KB.

Stage 6 — Verification + roll-up

After all stages land, re-run bash bloat esp32s3 --build and assert the total has dropped from 388,380 B to ≤ 280,000 B. Update docs/SLIM_ESP32S3.md with the final-state numbers and per-stage breakdown.

Total projected savings

Stage Savings Cumulative Cumulative %
Stage 0 0 0 0 %
Stage 1 ~55,000 55,000 14 %
Stage 2 ~3,000 58,000 15 %
Stage 3 ~12,000 70,000 18 %
Stage 4 ~4,000 74,000 19 %
Stage 5 ~750 74,750 19 %

Target: 388 KB → ≤ 280 KB. Projected achievement at 75 KB recovered: 313 KB ≈ 19 % reduction, falling short of the 28 % target. Closing the remaining ~33 KB needs Stage 3 to land at its upper bound (CONFIG_BT_ENABLED=n on builds where it's currently on, ~15 KB) plus a Stage 7 follow-on for the newlib printf engine (currently 50 KB; if FastLED-side TUs stop referencing snprintf we may pull in fewer of the 4 vfprintf variants — needs another audit pass after Stage 1 collapses the FL_WARN literals).

What's explicitly out of scope

These are intentionally not in this issue and need their own tracking issues:

Working branch

All Stage 1-6 PRs land on feat/esp32s3-bloat-reduction (already created). Each stage opens its own PR onto that branch; when all stages are green, the branch merges back to master as one squashed series.

Related

🤖 Generated with Claude Code

Activity

  1. moved this from Triage to Done in FastLED Trackeron Jun 7, 2026
  2. zackees commented on Jun 7, 2026

    @zackees
    MemberAuthor

    Re-issued with file:line-grounded specifics at #2886 — please track from there.

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