#2856·FastLED

Meta: ESP32-S3 binary-size reduction — Batch 3 (successor to #2773)

Author: zackeesCreated Jun 6, 2026Updated Sep 25, 2026
Labelsdeferred

Slim-bridge conversion moved to meta issue #4580 (2026-09-24)

The directive to convert every legacy addLeds<> controller (clockless and clocked, all platforms) to the slim bridge now lives in #4580. That issue has the evidence, the gap register, the testing plan, the exhaustive inventory, and 18 sub-issues (#4581-#4598). It is linked here as a sub-issue.


Summary

Successor to #2773, which shipped Batches 1+2 (~30 KB default-mode + ~22-43 KB opt-in via FASTLED_LOG_VERBOSITY=0 and FASTLED_RMT_STATIC_ALLOCATION=1). The cumulative #2773 work brought the ESP32-S3 NEOPIXEL Blink baseline from 673 KB → ~595-620 KB.

This issue scopes the next architectural round: items that #2773's closing comment classified as "structural to the post-#2420 ChannelManager/RMT architecture and won't close without deeper redesign." Each is bigger and riskier than a Batch 1/2 item, so they get their own issue.

Methodology change vs #2773. The local PIO toolchain proved fragile (cache wipe during disk cleanup left xtensa-esp32s3-elf-g++ + esptool.py missing). For this round, audit via CI artifacts instead of local builds:

  1. Push a branch with the candidate change.
  2. Open a PR that triggers the existing compile-many matrix.
  3. Extract firmware.bin / firmware.map from the CI artifact bundle.
  4. Compare against a same-SHA baseline build (no change) on the same matrix entry.

FastLED/fbuild#417 would make this push-button.


Tracking matrix

Item Est. savings Mechanism preventing auto tree-shake Status PR
3.1 Channel::showPixels Level B — template-trait static dispatch ~3-4 KB Linker drops whole functions only; need per-instantiation specialization not started —
3.2 fl::sstream operator<< → printf-style log backend ~5-10 KB Each FL_WARN/FL_LOG_RMT site instantiates a fresh sstream operator chain; printf path is one shared TU not started —
3.3 ChannelManager static-bind path for boot-time addLeds<>() ~5-10 KB Dynamic vtable dispatch through BusTraits<Bus::X>::instancePtr(); static path can pre-bind not started —
3.4 RMT5 encoder dedup across chipsets ~2-5 KB Each chipset gets its own encoder instantiation; multi-chipset sketches rare not started —
3.5 fl::result<T, E> → status code for internal-only APIs ~1-2 KB Discriminator + payload struct ABI vs single-register return not started —
3.6 fl::vector<ChannelAllocation> → fixed-size array under static-allocation ~1 KB Runtime vector carries growth machinery even when count is bounded not started —

Batch 3 post-merge projection: ~17-32 KB additional on top of Batch 2. Realistic post-everything baseline: ~565-605 KB (vs 3.10.3 baseline of 344 KB).


Items

3.1 Level B template-trait refactor of Channel::showPixels — ~3-4 KB

Carry-over from #2773 item 2.5 Level A → Level B (RFC posted there). Level A shipped as the FASTLED_RMT_STATIC_ALLOCATION opt-in macro (#2846). Level B replaces the macro with template-trait detection so the --gc-sections linker proves at link time which specialization is reachable, no user opt-in required.

Action: Make ChannelEngineRMTImpl<bool kStatic> a class template. Static specialization uses a slim allocateTxStatic + slim createChannel; dynamic specialization keeps current behavior. A kIsStaticInit thread-local flips false after setup() returns or first removeLeds() / late addLeds(). Static specialization is safe only before the flip; both specializations are emitted and the linker drops whichever the sketch doesn't reach.

Risk: Touches template instantiation in every example. Needs careful audit of test fixtures and mock peripheral injections (the #ifdef FASTLED_STUB_IMPL paths in channel_driver_rmt.cpp.hpp are already heavily #ifdef'd).


3.2 Printf-style log backend for FL_WARN / FL_LOG_RMT — ~5-10 KB

Every FL_WARN(X) call site at FASTLED_LOG_VERBOSITY=1 (the default) instantiates:

cpp
fl::println((fl::sstream() << ... << X).c_str())

Each operator<< chain compiles to a fresh sequence of fl::sstream::operator<<(...) calls per type. Across hundreds of FL_WARN sites in FastLED's libraries the operator<< specializations don't merge — they're per-translation-unit.

Action: Add a parallel fl::printf("fmt", args...) API and migrate the highest-density FL_WARN/FL_LOG_RMT sites. The format string lives in rodata once, the runtime decoder is one TU, and the call-site code shrinks to a single function call + arg push.

Caveat: fl::printf would need to route through fl::println (no link to libc printf) so we don't reintroduce the _svfprintf_r bloat killed in #2773 item 1.1.

Where to start: RMT5 channel_driver_rmt.cpp.hpp has ~20 FL_WARN/FL_LOG_RMT call sites with multi-line operator<< chains. That alone is plausibly ~2-3 KB.


3.3 Static-bind path for boot-time addLeds<>() — ~5-10 KB

The post-#2428 Channel<Bus, Chipset> API uses dynamic dispatch through BusTraits<Bus::X>::instancePtr(). For the common static-init scenario (one or two addLeds<>() calls in setup(), no later removal), the vtable indirection is dead weight.

Action: Re-add the legacy pre-#2428 pre-bind path as the default for addLeds<>() calls made before setup() returns. The dynamic API stays the path for late-bound add/remove. Same kIsStaticInit thread-local from #3.1 gates the choice at runtime; the linker drops the unused branch when only one is reachable per chipset×bus instantiation.

Risk: Large blast radius — every example uses addLeds<>(). Need to audit the test matrix carefully.


3.4 RMT5 encoder dedup across chipsets — ~2-5 KB

Each chipset (WS2812, WS2811, SK6812, APA102, …) gets its own encoder instantiation via mPeripheral.createEncoder(timing, FASTLED_RMT5_CLOCK_HZ). The body is small but the per-chipset instantiation is duplicated — and the timing struct varies only by a handful of uint16_ts.

Action: Move the encoder body to a single non-template function taking (const ChipsetTiming&, uint32_t clock_hz). The current call site already passes those args; the change is mostly removing template syntax sugar.

Audit risk: Need to verify the encoder isn't relying on type-level distinctions anywhere downstream (it shouldn't — the RMT peripheral takes a void* encoder handle).


3.5 fl::result<T, E> → status code for internal-only APIs — ~1-2 KB

result<size_t, RmtMemoryError> is a sum-type with a discriminator + the payload. For internal-only APIs (e.g. RmtMemoryManager::allocateTx is called only from ChannelEngineRMT::createChannel), the ABI cost is real: 2 registers in/out vs 1, extra branch on the discriminator at each call site.

Action: Add an internal-API overload returning size_t with sentinel value (0 = failed). Keep the public result<> API stable. Wire createChannel through the new internal path.

Risk: Low. The result<> API is well-tested; the internal overload would be a thin wrapper.


3.6 Fixed-size allocation ledger under FASTLED_RMT_STATIC_ALLOCATION — ~1 KB

When FASTLED_RMT_STATIC_ALLOCATION=1 (#2846), the user has asserted "one fixed strip, boot-time init, no dynamic add/remove." Under that contract, fl::vector<ChannelAllocation> allocations is overkill — a single ChannelAllocation field would do. The vector pulls its growth machinery (reserve, push_back, erase) into the static binary even when only one element is ever stored.

Action: Under FASTLED_RMT_STATIC_ALLOCATION, replace mLedger.allocations with a fl::array<ChannelAllocation, SOC_RMT_TX_CANDIDATES_PER_GROUP> + a count.

Caveat: Less reach than #3.5; the savings depend on whether vector's machinery is already shared with other vector instantiations in the binary.


Methodology — how to audit Batch 3 PRs

Local builds are unreliable (toolchain cache fragile). Run the audit via CI artifacts:

bash
# 1. Push the candidate change to a branch.
git push -u origin feat/2818-3.1-channel-static-dispatch

# 2. Trigger compile-many via PR; let CI run.
gh pr create --base master --title "..." --body "..."

# 3. After CI completes, fetch the firmware.bin artifact.
RUN=$(gh run list --branch feat/2818-3.1-channel-static-dispatch --workflow build --limit 1 --json databaseId --jq '.[0].databaseId')
gh run download $RUN --name esp32s3-firmware --dir /tmp/audit

# 4. Same for a same-SHA baseline build.
# (Either compare against master's last successful build artifact,
#  or push an empty commit on the branch and compare side-by-side.)

A future fbuild audit-esp32s3-blink subcommand (FastLED/fbuild#417) would make this push-button.


Related issues / prior work

  • #2773 — Batch 1+2 (closed; this issue's parent)
  • #2473 — Master tracking issue (+313 KB delta vs 3.10.3)
  • #2771 — Original (corrected) version of #2773
  • #2428 — ChannelManager refactor (the architectural source of much of the remaining ~250 KB delta)
  • FastLED/fbuild#417 — push-button binary-size audit subcommand