Skip to content

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

Open
0 of 1 issue completed

Description

@zackees

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:

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:

# 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

Sub-issues

Sub-issues

0 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. zackees commented on Jun 6, 2026

    @zackees
    MemberAuthor

    /clud-pr status update

    Working through this meta. The clud-pr skill's "one PR per task" rule conflicts with a meta covering 6 architecturally-independent items, so the split chosen is: ship every item that fits in a single PR immediately as its own PR; defer multi-day items to dedicated follow-ups.

    Shipped (open PRs)

    Item PR Scope
    3.6 Fixed-size ledger under FASTLED_RMT_STATIC_ALLOCATION #2861 free() / freeDMA() become no-ops under the macro, killing fl::vector_inlined::erase + diagnostic FL_LOG_RMT/FL_WARN operator<< chains
    3.5 tryAllocateTx / tryAllocateRx status-code variants #2862 Wrappers bypass result<size_t, RmtMemoryError> ABI at the 4 internal callers; public result<>-bearing API retained

    Already done before #2856 was filed

    Item Why
    3.4 RMT5 encoder dedup across chipsets The encoder is already a runtime virtual on IRMT5Peripheral::createEncoder(const ChipsetTiming&, u32), not templated per-chipset. The byte estimate in the original tracking matrix doesn't apply.

    Deferred to dedicated PRs

    These each need their own multi-day PR with its own scoping pass — landing speculative scaffolding under a /clud-pr would be wrong:

    Item Why deferred
    3.1 Level B template-trait refactor of Channel::showPixels Design RFC already at #2773 comment 4636464324. Requires ChannelEngineRMTImpl<bool kStatic> template + a kIsStaticInit thread-local + careful audit of every example's addLeds<> instantiation. Multi-day.
    3.2 Printf-style log backend Requires a new fl::printf API surface (not present today; can't reuse libc printf without re-pulling _svfprintf_r killed by #2773 item 1.1). Then bulk migration of ~hundreds of FL_WARN/FL_LOG_RMT sites. Multi-day.
    3.3 Static-bind path for boot-time addLeds<>() Largest blast radius — touches every example. Needs a full audit of the test matrix to avoid regressions. Multi-day.

    Each of these warrants its own focused issue rather than living under this meta.

    Recommendation

    After #2861 and #2862 land, close this meta and re-open 3.1, 3.2, 3.3 as three standalone issues so each one's design discussion happens in isolation. The meta as currently scoped is partially redundant (item 3.4 was a misread of current state) and contains items at incompatible scales (3.5/3.6 are PR-sized; 3.1/3.2/3.3 are sprint-sized).

  2. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Triage pass:

    No progress since filing — all 5 tracking-matrix items (3.1 template-trait static dispatch / 3.2 sstream→printf / 3.3 ChannelManager static bind / 3.4 RMT5 encoder dedup / 3.5 partial) show "not started" with no PR.

    Each is genuinely architectural work — not the knob-flip / sdkconfig variety of #2773's first two batches. Estimated savings per item are 2-10 KB; cumulative if all five ship would be ~20-40 KB on top of #2773's already-shipped 50-80 KB.

    Recommendation: the work is still relevant in principle, but "not started" 10 days after filing suggests it's a backlog rather than an active workstream. Two options:

    1. Convert to a backlog label, close meta — re-file each of 3.1-3.5 as a standalone issue if/when someone picks it up. Avoids the meta accumulating staleness signals while leaving the analysis intact in the comments / history.
    2. Resource it — pick one item (3.4 is the lowest-risk; 3.2 is the highest-ROI) and use it to revive momentum.

    Standing by — happy to pick up 3.4 (RMT5 encoder dedup) as an off-bench piece if you confirm it doesn't overlap with the bloat band work in #2974.

  3. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    B3 of meta #3122 investigation:

    Looked at the actual code. Rmt5EncoderImpl::create(ChipsetTiming, resolution_hz) in src/platforms/esp/32/drivers/rmt/rmt_5/rmt5_peripheral_esp.cpp.hpp:556 is already runtime-parameterized by ChipsetTiming — there's no per-chipset encoder template instantiation to dedup at the encoder level.

    The 58 KB per-chipset symbol from #2886's top-25 (fl::ClocklessIdf5<3, WS2812_800KHZ, GRB, 0, false, 280>::ClocklessIdf5()) comes from the outer ClocklessIdf5<DATA_PIN, TIMING, RGB_ORDER, XTRA0, FLIP, WAIT_TIME> template — specifically the transitive FL_WARN/FL_LOG closure pulled in by the ctor (75 sites in channel_driver_rmt.cpp.hpp, 59 in rmt_memory_manager.cpp.hpp). Stage 1 of #2886 (FASTLED_LOG_VERBOSITY=0) already addresses the lion's share of that.

    Item 3.4 as stated is essentially complete — the encoder isn't duplicated per chipset; what looked like duplication is the FL_WARN cluster, which #2886's Stage 1 handled.

    Recommendation: ✅ close item 3.4 as superseded by #2886 Stage 1 (#2890). If multi-chipset sketches are still showing per-chipset weight after Stage 1 is applied, the duplication is at the outer ClocklessIdf5 template level — a different problem than "encoder dedup" and would need its own focused issue.

    (B3 in #3122 ticked accordingly.)

  4. zackees commented on Jun 16, 2026

    @zackees
    MemberAuthor

    Item 3.2 (fl::sstream operator<< → printf-style log backend) is now tracked as standalone issue #3158, with the API contract, format-string safety story, NANO-compat audit plan, and call-site migration roadmap. This is the highest-ROI item of #2856 (~5-10 KB on ESP32-S3 Blink) and needed proper scoping rather than rundown-row execution.

  5. added
    deferred
    on Aug 20, 2026
  6. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Triaged against current master ad40fd2.

    Marking deferred: this meta is not resolved, but its remaining work is architectural and spans independent efforts rather than one bounded fix.

    Current evidence:

    Restart when the size gate is green under one same-SHA production-representative measurement contract, then split 3.1 and 3.6 into bounded design-backed issues with lifecycle/capacity tests and explicit size targets.

  7. zackees commented on Sep 24, 2026

    @zackees
    MemberAuthor

    Updated the issue description with a directive: all legacy clockless and clocked (SPI) addLeds controllers move to the slim bridge format (plain CPixelLEDController + owned ChannelData, registered with ChannelManager, not an fl::Channel). Evidence is draft #4576: ESP32-S3 Blink −22.5 KB, and it passes AutoResearch on an ESP32-C6. The per-controller checklist is at the top of the description.

  8. zackees commented on Sep 24, 2026

    @zackees
    MemberAuthor

    Added a Known gaps of the slim bridge register to the description, based on a 7-way code audit of draft #4576. It records regressions, pre-existing gaps and coverage gaps, and each entry is marked verified-in-code or inferred. It is a register, not a fix list. The two highest-impact items:

    • A1: a disabled or non-exclusive driver can stall a legacy strip.
    • B1: ClocklessIdf4 and ClocklessSPI never register with ChannelManager, so their data is likely never transmitted today.
  9. zackees commented on Sep 24, 2026

    @zackees
    MemberAuthor

    Added a Testing plan section. It maps every gap in the register (A1-A12, B1-B5, C1-C2) to a host unit test. The key prerequisite (T0) is extracting one shared, host-compilable SlimBridgeController template, so host tests exercise the same code the ESP32 builds use. Per-platform controllers then become thin DriverTraits aliases that all run one conformance suite. The acceptance criteria now require passing that suite.

  10. zackees commented on Sep 25, 2026

    @zackees
    MemberAuthor

    The directive now covers every platform, not only ESP32. It adds:

    • an exhaustive inventory of all 62 legacy clockless controller files, classified as Heavy (fl::Channel), unregistered-slim (the B1 bug class), compliant, or pure legacy;
    • a temporary SlimBridgeChecker lint that fails every non-compliant controller until its platform converts, and is deleted once the inventory is empty.

    Pure bit-bang targets (AVR, ATtiny and others) would use a manager-free "Direct" DriverTraits, so the conversion adds no flash there. Whether they convert now or are exempted is left as an open decision.

  11. zackees commented on Sep 25, 2026

    @zackees
    MemberAuthor

    The slim-bridge directive, gap register, testing plan and inventory moved to the new meta issue #4580, which is linked as a sub-issue. Tracking uses native sub-issues (#4581-#4598) rather than a checked-in lint, so master is never turned red.

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