Skip to content

Channels API: cut add<Bus>() flash overhead vs addLeds<> by 50% (ESP32-C6: +47 KB) #5157

Closed

Description

@zackees

Summary

On ESP32-C6, the typed Channels path FastLED.add<fl::Bus::AUTO>(cfg) costs +46,962 B image flash / +1,067 B attributed RAM over the classic FastLED.addLeds<WS2812, PIN, GRB>(leds, N) driving the same strip on the same backend (PARLIO). Goal: cut that overhead by ≥50% (≥23.5 KB flash) in shared code, with no functional regression.

The erased FastLED.add(cfg) (+139,768 B) is out of scope: it deliberately enrolls every driver for runtime selection (#2459). add<Bus>() is the recommended path.

Measurements (esp32c6, bash bloat, fbuild 2.5.51, IDF 5.5.1, -Os, 60× WS2812 GPIO3, no Serial)

Variant Image flash Attributed RAM
A addLeds<WS2812,3,GRB> 353,990 18,054
C add<Bus::AUTO>(ChannelConfig) 400,952 19,121
C − A +46,962 +1,067
B add(ChannelConfig) (erased, reference) 493,758 20,687

Candidates (behavior-preserving, shared code)

  1. Protocol encoder fanout. Channel::selectPixelEncoder (src/fl/channels/channel.cpp.hpp:214-264) takes the address of every clockless/SPI encoder, so a WS2812 channel retains encodeUCS7604 (948 B), Gamma8Impl/Gamma8::getOrCreate, GAMMA_2_8_LUT and the gamma16 LUT (~5.8 KB). Bind the encoder from the chipset type at the typed construction boundary; keep the erased selector for runtime chipsets. Est. 5–10 KB.
  2. Channel event lists. Nine fl::function_list lists in channel_events.h are always invoked, with invoke/compact/sort instantiated per signature (~8.4 KB by name, 364 B static RAM). Share the non-template list machinery and keep a zero-cost no-subscriber path. Preserve priority, removal during dispatch and late subscription. Est. 3–7 KB.
  3. RGBW power/convert hooks on RGB channels. Channel::syncLegacySettings (channel.cpp.hpp:391-410) references enable_rgbw_power_estimate / RGBW conversion, retaining the RGBW estimator and a 513 B scaling LUT cache without any limiter. Install these only when RGBW is configured, keeping the direct mWhiteCfg assignment semantics. Est. 0.8–2 KB flash, 517 B RAM.
  4. Diagnostics. Long FL_ERROR strings in resolveDynamicDriver, emitDisabledDriverError and the manager. Share fragments and keep the messages useful. Est. 1–5 KB.
  5. Driver resolution / profile plumbing. resolveDynamicDriver, selectDriverForChannel, reconcileColorProfile. Pin the driver for typed channels, invalidated on registry or config change. Est. 0.4–1.5 KB.

Acceptance

  • Re-measure A vs C with identical wrapper, profile and toolchain; C − A flash ≤ 23,481 B.
  • bash test --cpp green; channel, manager, event, power, color-profile, wave3/wave8 and spi_legacy_golden tests unchanged or strengthened.
  • fbuild build + deploy + on-device test of the C sketch on an attached ESP32-C6 (pixels output via AutoResearch).
  • No change to erased add(cfg) semantics.

Investigation artifacts: phase-1 report by a Codex worker (A/B/C ELFs, maps, symbol deltas).

Activity

  1. added
    sanitized
    on Nov 8, 2026
  2. zackees commented on Nov 8, 2026

    @zackees
    MemberAuthor

    Maintainer directive: build-file changes for PR #5163

    The maintainer (repo owner) authorized these build changes in the coordinating session on 2026-11-08, choosing "Authorize, post directive":

    1. src/fl/channels/_build.cpp.hpp: include the new encoder_availability.cpp.hpp. The library alone owns FASTLED_DISABLE_* encoder availability, which fixes the ODR mismatch between the typed and erased paths.
    2. src/fl/stl/_build.cpp.hpp: the unity-router include for the function_list support code.
    3. tests/meson.build: no-PCH flags for the fl_channels_encoder_availability and fl_stl_function_list tests (caller macros intentionally differ from the library's), plus the probed allocator --wrap used by the allocation-failure test.

    The directive covers only these changes, which exist to support the new source file and the regression tests in #5163.

  3. moved this from Triage to Done in FastLED Trackeron Nov 22, 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

    sanitized

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions