Skip to content

Cut ClocklessIdf5 bloat via FASTLED_DISABLE_SPI_CHIPSETS gate (~1 KB) (#2886) #2913

Closed

Description

@zackees

Goal

Cut bytes attributed to fl::ClocklessIdf5<...>::ClocklessIdf5() (top-1 symbol, 48,002 B map-derived) by gating the SPI dispatch branch in fl::Channel::showPixels behind an opt-in build flag FASTLED_DISABLE_SPI_CHIPSETS=1. For NEOPIXEL-only sketches (the stock Blink case), users opt in and the linker dead-strips ~5 PixelIterator SPI encoder methods that are otherwise statically reachable from showPixels.

Parent: #2886 — third algorithmic-bloat reduction targeting symbols reachable from the ClocklessIdf5 static-init closure.

Why this is a real win

fl::Channel::showPixels at src/fl/channels/channel.cpp.hpp:486-557 has two branches gated by runtime mChipset.is<>() checks:

if (mChipset.is<ClocklessChipset>()) {
    // 2-case switch: WS2812 or UCS7604
} else if (mChipset.is<SpiChipsetConfig>()) {
    // 11-case switch: APA102 / DOTSTAR / SK9822 / WS2801 / WS2803 /
    // P9813 / LPD8806 / LPD6803 / SM16716 / HD108 / HD107 / ...
}

For a stock NEOPIXEL Blink sketch, mChipset is always ClocklessChipset and the SPI branch is dynamically unreachable, but the compiler can't prove that — every pixelIterator.writeXXX(...) reference in the SPI branch is statically reachable, so the linker keeps the encoder bodies alive.

Measured cost (post-#2911 ELF, master @ f090358d76)

The 4-5 dead-code PixelIterator SPI encoder symbols currently linked into a NEOPIXEL Blink:

Symbol Size
fl::PixelIterator::writeLPD8806<fl::vector_psram<u8>> 235 B
fl::PixelIterator::writeSK9822<fl::vector_psram<u8>> 197 B
fl::PixelIterator::writeAPA102<fl::vector_psram<u8>> 197 B
fl::PixelIterator::writeSM16716<fl::vector_psram<u8>> 91 B
Total 720 B

Plus the showPixels body itself shrinks by the switch-table footprint (~300-500 B for an 11-case switch on xtensa).

Conservative projected saving: ~1.0-1.2 KB on NEOPIXEL Blink builds.

writeWS2812 (the live encoder on Blink, 277 B) stays.

Deliverable

src/fl/channels/channel.cpp.hpp — gate the SPI branch

 if (mChipset.is<ClocklessChipset>()) {
     // ... clockless dispatch unchanged ...
+#if !defined(FASTLED_DISABLE_SPI_CHIPSETS) || !FASTLED_DISABLE_SPI_CHIPSETS
 } else if (mChipset.is<SpiChipsetConfig>()) {
     // ... SPI 11-case dispatch unchanged ...
+#endif
 }

The !defined() || !FLAG form keeps the default unchanged for users who haven't set the flag.

Behavior when the flag is set

If a user sketch sets FASTLED_DISABLE_SPI_CHIPSETS=1 AND uses FastLED.addLeds<APA102, ...> (or any SPI chipset), the SPI dispatch is gone — calling showPixels on that channel silently emits nothing. This is the same trade-off as Stage 2's FASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT: opt-in, with the user accepting the constraint that they're not using SPI chipsets.

Document the constraint clearly in:

Acceptance

  1. FASTLED_DISABLE_SPI_CHIPSETS=1 build flag gates the SPI branch in Channel::showPixels.
  2. bash lint --cpp passes.
  3. Default behavior (flag unset) unchanged — existing examples using APA102 / SK9822 / etc. continue to work.
  4. Measured against the post-perf(gamma): use fl::s16x16::pow for Gamma8 LUT + applyGamma_video; drop __ieee754_pow #2911 ELF baseline (347,004 B), a -DFASTLED_DISABLE_SPI_CHIPSETS=1 build of NEOPIXEL Blink should be ~1.0-1.2 KB lower. Default-flag build should be unchanged within ±50 B.
  5. docs/SLIM_ESP32S3.md priority table gains a row 6 for the new flag.

Out of scope

  • Auto-detecting whether SPI chipsets are used at compile time. That requires the template-trait static dispatch refactor in Meta: ESP32-S3 binary-size reduction — Batch 3 (successor to #2773) #2856 item 3.1, much larger blast radius.
  • The clockless UCS7604 branch — that's a different (smaller) opt-in.
  • Examples / library.properties advertising the flag — initial scope is the gate + doc.

Related

🤖 Generated with Claude Code

Activity

  1. moved this from Triage to Done in FastLED Trackeron Jun 7, 2026
  2. added a commit that references this issue on Jun 7, 2026
    74bc797
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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions