Skip to content

ESP32-S3 binary size: item 2.5 Level B — ChannelEngineRMTImpl template-trait fixed allocation (~3-4 KB, deferred from #2773) #2864

Open

Description

@zackees

Background

Carved out from the closeout of #2773 (ESP32-S3 binary-size meta). Level A of item 2.5 (FASTLED_RMT_STATIC_ALLOCATION opt-in macro) shipped in #2846; the bulk of the FL_LOG_RMT/FL_WARN rodata was already collapsed by item 2.3 (FASTLED_LOG_VERBOSITY=0, #2791). What remains is the automatic (non-opt-in) tree-shake of the runtime memory planner — Level B of the RFC at #2773 (comment).

This issue tracks Level B as its own multi-day design pass so the parent meta can close.

Goal

Let the linker prove which planner specialization a sketch needs and drop the other, without requiring the user to define a macro.

Estimated win on stock ESP32-S3 NEOPIXEL Blink: ~3–4 KB code on top of everything already shipped under #2773.

Why Level A doesn't cover this

Level A (#2846) requires the user to define FASTLED_RMT_STATIC_ALLOCATION=1 before including <FastLED.h>. That captures the ~70 % of users who actively tune binary size, but does nothing for the default build. The functions still on the live binary's hit list:

  • RmtMemoryManager::calculateMemoryBlocks(bool) — memory-pressure detection loop, network/idle strategy selection, platform-cap enforcement.
  • RmtMemoryManager::allocateTx(...) hot path — DMA-vs-non-DMA branch, tryAllocateWords, ledger push.
  • RmtMemoryManager::freeDMA(u8, bool) — small but unconditionally reachable from ~ChannelEngineRMTImpl.

The reason these can't be tree-shaken today is that the destructor at channel_driver_rmt.cpp.hpp:142 unconditionally calls memMgr.freeDMA(...) and memMgr.free(...), which pulls the whole planner ledger machinery in via instance-singleton + allocations vector reachability.

Proposed design

Make ChannelEngineRMTImpl<bool kStatic> a class template:

  • kStatic = true specialization (default at startup before any other addLeds<> is seen): slim createChannel that calls a separate allocateTxStatic member — single tryAllocateWords + ledger push, no planner, no diagnostics.
  • kStatic = false specialization: current behavior (full planner, network-coex, recovery).

Detection happens through a bool kIsStaticInit thread-local that flips to false after setup() returns or the first removeLeds() / late addLeds() is observed. The static specialization is only safe before that flip; both specializations are generated and the linker drops whichever the sketch doesn't reach.

Risks

  • Blast radius — touches template instantiation in every example sketch that uses ESP32 RMT5.
  • Test fixtures / mock peripheral injection — needs careful audit so unit tests still resolve the right specialization.
  • Maintenance cost — two specializations means two code paths to keep in sync for any future RMT5 change. Counter: the static one is much simpler, so divergence is bounded.
  • Detection edge case — defining "setup() has returned" portably without an explicit user hook. May need a static int kInitDepth guard in addLeds<> that's incremented/decremented around the call, with the flip happening once depth returns to 0 after the first non-zero entry.

Out of scope

Acceptance criteria

  • Stock ESP32-S3 examples/Blink/Blink.ino build drops by ≥3 KB in firmware.bin (no user macros set) vs current master.
  • All in-tree examples that use ESP32 RMT5 still compile.
  • bash test --cpp green.
  • No regression on builds that set FASTLED_RMT_STATIC_ALLOCATION=1 (feat(rmt5): FASTLED_RMT_STATIC_ALLOCATION opt-in macro (#2773 item 2.5 Level A) #2846 path still works the same way).
  • No regression on builds that exercise the dynamic path (removeLeds() or late addLeds()).

References

Activity

  1. added
    deferred
    on Aug 20, 2026
  2. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Triaged against current master ad40fd2.

    Marking deferred: the requested automatic no-macro ChannelEngineRMTImpl static specialization has not landed and remains a speculative cross-layer redesign, not a bounded fix.

    Current evidence:

    • FASTLED_RMT_STATIC_ALLOCATION still defaults to 0; ChannelEngineRMTImpl is non-template; one factory always constructs the same implementation.
    • There is no kIsStaticInit/setup-return hook, compile-time static factory, or automatic-specialization test.
    • The existing explicit macro measured only about 908 B saved, well below the original 3-4 KB target, and there is no current same-SHA proof that 3 KB remains recoverable.
    • The design must preserve runtime add/remove, pooled RMT channels, network reconfiguration, DMA accounting, RX/TX ledger sharing, rollback, reuse, and teardown across RMT5 targets.

    Restart with a fresh same-toolchain A/B symbol audit. Continue only if the target is still evidence-backed, then revise the RFC around a truly compile-time factory boundary and add focused static/dynamic lifecycle tests plus S3/C3/C6/H2/P4 validation.

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

    deferred

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions