Skip to content

perf: RGBW/RGBWW pixel paths linked into RGB-only sketches (~1.5 KB on ESP32) #4795

Closed

Description

@zackees

Problem

RGB-only sketches (Blink: one NEOPIXEL) link the RGBW/RGBWW pixel paths on every ESP32: about 1.5–1.7 KB per sketch.

  • esp32dev Blink: ScaledPixelIteratorRGBWW::advance 219, PixelControllerVtable<…>::loadAndScaleRGBWW 219, ScaledPixelIteratorRGBW::advance 175, loadAndScaleRGBW 296, rgbww_partial_reorder 110, LegacySettings::rgbw()/rgbww() 84/74.
  • SPI sketches: they additionally link loadAndScaleRGBWUnordered and rgb_2_rgbww_user_function.

Proposed fix

Find what makes these reachable when RGBW is never enabled, likely the PixelControllerVtable storing every loader or the LegacySettings::rgbw() dispatch. Only install the RGBW/RGBWW loaders when setRgbw() or the RGBWW API is actually called (link-on-use, same idea as the clockless encoder sub-issue).

Acceptance

  • These symbols are absent from Blink and APA102 maps on esp32dev and S3.
  • RGBW examples are unchanged.

Data: https://fastled.github.io/dashboard/ (master 18669e6 vs 3.10.3, fbuild 2.5.38), symbol-level bloat reports linked from each dashboard point.

Activity

  1. added
    type: regression
    priority: medium
    platform: esp32
    on Oct 9, 2026
  2. zackees commented on Oct 9, 2026

    @zackees
    MemberAuthor

    Investigated during the #4801 pass; deferred as it needs a design change, not a local fix.

    Why it's linked: PixelIterator's constructor (src/fl/chipsets/encoders/pixel_iterator.h) takes the address of RgbwLoadBinder<T>'s RGBW/RGBWW thunks for every source type. The encoders (writeWS2812 and friends) branch on Rgbw::active() at runtime, so ScaledPixelIteratorRGBW(W)::advance, rgbww_partial_reorder and the thunks are always reachable.

    Why the obvious fix doesn't work: RGBW can't be derived from the already-bound loadAndScaleRGB thunk. PixelController::loadAndScaleRGBWUnordered reads raw mData with premixed scaling and no dithering, while loadAndScaleRGB dithers, so the output bytes would differ.

    Workable direction:

    1. Replace the per-type RGBW/RGBWW thunks with one tiny per-type "raw pixel + premixed scale" thunk, and do rgb_2_rgbw/rgb_2_rgbww plus the reorder in the type-erased layer.
    2. Reach the RGBW encode loops through a pointer installed by CLEDController::setRgbw() / the RGBWW setter (link-on-use, same pattern as perf(esp32): APA102 SPI sketches link the clockless half of the unified FLEX_IO engine (~8-10 KB flash) #4793), so RGB-only programs never name them.

    This needs byte-exact golden tests for every colour order and W placement before landing.

  3. zackees commented on Oct 9, 2026

    @zackees
    MemberAuthor

    Second attempt (2026-10-09). Measured on master 50c99f0210 esp32dev Blink: about 2.0 KB of RGBW/RGBWW code is still linked. That includes PixelControllerVtable::loadAndScaleRGBW (296 B) and loadAndScaleRGBWW (219 B), ScaledPixelIteratorRGBW(W)::advance (175/219 B), the rgb_2_rgbw_* modes and rgbw(w)_partial_reorder. The call graph is PixelIterator::writeWS2812 → runtime mRgbww.active() / mRgbw.active() branches, plus thunk addresses taken in the PixelIterator constructor.

    I tried gating a link-on-use hook at the point RGBW becomes active, and it isn't viable without an API change:

    • a default-constructed Rgbw is active (kRGBWExactColors), and RgbwInvalid derives from Rgbw, so a constructor hook fires in every sketch;
    • rgbw_mode is a public field, so RGBW can be switched on by assignment with no hook;
    • setRgbw() is not the only entry point (Channel options, LegacySettings).

    Prerequisite: encapsulate Rgbw/Rgbww activation (a private mode with a setter), then install the RGBW encode path from that setter. Land it with byte-exact golden tests across colour orders and W placements.

  4. zackees commented on Oct 9, 2026

    @zackees
    MemberAuthor

    The prerequisite API change is now tracked separately in #4815.

  5. moved this from Triage to Done in FastLED Trackeron Oct 9, 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

    platform: esp32priority: mediumtype: regression

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions