Skip to content

perf(esp32): gate SPI dispatch in Channel::showPixels behind FASTLED_DISABLE_SPI_CHIPSETS - #2914

Merged
zackees merged 1 commit into
masterfrom
feat/2913-disable-spi-chipsets
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2913-disable-spi-chipsets

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

perf(esp32): gate SPI dispatch in Channel::showPixels behind FASTLED_DISABLE_SPI_CHIPSETS

Closes #2913.

Adds an opt-in build flag FASTLED_DISABLE_SPI_CHIPSETS=1 that gates
the SPI dispatch branch in fl::Channel::showPixels. For NEOPIXEL-only
sketches the SPI branch is dynamically unreachable, but the compiler
cannot prove that — every pixelIterator.writeXXX(...) reference
inside the 11-case switch is statically reachable, keeping ~720 B of
encoder bodies and the switch-table footprint linked.

Measured baseline (post-#2911, master @ 6bd4ebd9ec)

Dead-code 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 xtensa switch). Projected total saving:
~1.0-1.2 KB on a NEOPIXEL Blink build with the flag enabled.

Behavior

  • Flag unset (default): No change. The SPI dispatch is present;
    every existing example using APA102 / SK9822 / etc. continues to
    work.
  • Flag set (-DFASTLED_DISABLE_SPI_CHIPSETS=1): The SPI branch is
    removed at preprocess time. showPixels() on a channel whose
    chipset is an SpiChipsetConfig falls through to the post-dispatch
    event emission with no data encoded — the channel silently emits
    nothing. Users opt in with the understanding that they're not
    using SPI chipsets in this build.

This mirrors the opt-in build-flag pattern shipped in #2894
(Stage 2 / boot-banner shim) — minimal default-change risk, real
savings for users who can accept the constraint.

Files

  • src/fl/channels/channel.cpp.hpp — #if !defined(FASTLED_DISABLE_SPI_CHIPSETS) || !FASTLED_DISABLE_SPI_CHIPSETS
    wraps the else if (mChipset.is<SpiChipsetConfig>()) block. The
    gate's behavior + savings are documented inline at the comment block
    above the branch.
  • docs/SLIM_ESP32S3.md — adds row 6 to the "Release-build flash
    savers" priority table with the new flag, its constraint, and PR
    link.

Verification

  • bash lint --cpp → all C++ linting checks pass.
  • The flag follows the established opt-in pattern; default behavior
    unchanged.
  • Measured saving will be validated on the post-merge build (a
    -DFASTLED_DISABLE_SPI_CHIPSETS=1 build of Blink, compared against
    the current 347,004 B baseline).

Expected savings

  • Eliminated: writeAPA102 (197 B), writeSK9822 (197 B), writeLPD8806
    (235 B), writeSM16716 (91 B) = 720 B (PixelIterator SPI encoders
    reachable only from showPixels' SPI branch).
  • Eliminated: ~300-500 B of switch-table + dispatch code in
    showPixels body.
  • Net: ~1.0-1.2 KB projected on NEOPIXEL Blink with flag set.

The Stage 6 regression gate (tests/test_esp32s3_bloat_regression.py,
baseline = 347004) does NOT change in this PR because it measures
the default-flag build, which is unchanged. A separate follow-up
records the flag-on measured number once a measurement run lands.

Refs #2886, #2913, #2908, #2911.

Summary by CodeRabbit

  • Documentation

    • Added build flag reference for configuring SPI chipset support options
  • New Features

    • Enabled conditional SPI chipset encoding based on build configuration flag

…DISABLE_SPI_CHIPSETS

Closes #2913.

Adds an opt-in build flag `FASTLED_DISABLE_SPI_CHIPSETS=1` that gates
the SPI dispatch branch in `fl::Channel::showPixels`. For NEOPIXEL-only
sketches the SPI branch is dynamically unreachable, but the compiler
cannot prove that — every `pixelIterator.writeXXX(...)` reference
inside the 11-case switch is statically reachable, keeping ~720 B of
encoder bodies and the switch-table footprint linked.

## Measured baseline (post-#2911, `master @ 6bd4ebd`)

Dead-code 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 xtensa switch). Projected total saving:
**~1.0-1.2 KB** on a NEOPIXEL Blink build with the flag enabled.

## Behavior

- **Flag unset (default):** No change. The SPI dispatch is present;
  every existing example using APA102 / SK9822 / etc. continues to
  work.
- **Flag set (`-DFASTLED_DISABLE_SPI_CHIPSETS=1`):** The SPI branch is
  removed at preprocess time. `showPixels()` on a channel whose
  chipset is an `SpiChipsetConfig` falls through to the post-dispatch
  event emission with no data encoded — the channel silently emits
  nothing. Users opt in with the understanding that they're not
  using SPI chipsets in this build.

This mirrors the opt-in build-flag pattern shipped in #2894
(Stage 2 / boot-banner shim) — minimal default-change risk, real
savings for users who can accept the constraint.

## Files

- `src/fl/channels/channel.cpp.hpp` — `#if !defined(FASTLED_DISABLE_SPI_CHIPSETS) || !FASTLED_DISABLE_SPI_CHIPSETS`
  wraps the `else if (mChipset.is<SpiChipsetConfig>())` block. The
  gate's behavior + savings are documented inline at the comment block
  above the branch.
- `docs/SLIM_ESP32S3.md` — adds row 6 to the "Release-build flash
  savers" priority table with the new flag, its constraint, and PR
  link.

## Verification

- `bash lint --cpp` → all C++ linting checks pass.
- The flag follows the established opt-in pattern; default behavior
  unchanged.
- Measured saving will be validated on the post-merge build (a
  `-DFASTLED_DISABLE_SPI_CHIPSETS=1` build of Blink, compared against
  the current `347,004 B` baseline).

## Expected savings

- Eliminated: writeAPA102 (197 B), writeSK9822 (197 B), writeLPD8806
  (235 B), writeSM16716 (91 B) = 720 B (PixelIterator SPI encoders
  reachable only from showPixels' SPI branch).
- Eliminated: ~300-500 B of switch-table + dispatch code in
  `showPixels` body.
- Net: ~1.0-1.2 KB projected on NEOPIXEL Blink with flag set.

The Stage 6 regression gate (`tests/test_esp32s3_bloat_regression.py`,
baseline = `347004`) does NOT change in this PR because it measures
the default-flag build, which is unchanged. A separate follow-up
records the flag-on measured number once a measurement run lands.

Refs #2886, #2913, #2908, #2911.
@zackees
zackees merged commit 74bc797 into master Jun 7, 2026
6 of 8 checks passed
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9841a314-b3ce-459a-a9ab-0e6c99e1aeed

📥 Commits

Reviewing files that changed from the base of the PR and between 6bd4ebd and cf105ae.

📒 Files selected for processing (2)
  • docs/SLIM_ESP32S3.md
  • src/fl/channels/channel.cpp.hpp

📝 Walkthrough

Walkthrough

This PR implements the FASTLED_DISABLE_SPI_CHIPSETS compile-time build flag to reduce flash usage on ESP32-S3 by removing SPI-chipset encoder code reachable from Channel::showPixels(). When enabled, the flag gates out the entire SPI dispatch branch, benefiting NEOPIXEL-only sketches; when disabled (default), behavior is unchanged.

Changes

SPI Chipset Encoding Compile-Time Gate

Layer / File(s) Summary
Conditional SPI encoding and documentation
src/fl/channels/channel.cpp.hpp, docs/SLIM_ESP32S3.md
Channel::showPixels() wraps the SPI chipset dispatch and its 11-case switch in #if !defined(FASTLED_DISABLE_SPI_CHIPSETS) || !FASTLED_DISABLE_SPI_CHIPSETS guards with comments explaining that SPI channels silently produce no output when the flag is enabled. The docs/SLIM_ESP32S3.md flash-savings table gains a row documenting the flag, its clockless-only requirement, and ~1.0–1.2 KB projected savings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • FastLED/FastLED#2913: This PR directly implements the deliverables specified in issue #2913 — adding the FASTLED_DISABLE_SPI_CHIPSETS=1 build flag gate and documenting it in docs/SLIM_ESP32S3.md.
  • FastLED/FastLED#2886: This PR implements a Stage 4 bloat-reduction strategy targeting the same Channel::showPixels() function and build-time define identified in the parent ESP32-S3 binary-size reduction plan.
  • FastLED/FastLED#2856: Both this PR and issue #2856 modify Channel::showPixels(); this PR applies a tactical preprocessing gate, while #2856 targets a longer-term template/static-dispatch refactor of the same function.

Possibly related PRs

Poem

🐰 A flag to turn away SPI's call,
Makes NEOPIXEL binaries small,
With preprocessor's gentle gate,
Flash bytes simply dissipate.
Clockless sketches now are light,
Blinks that fit just right! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2913-disable-spi-chipsets

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 7, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 7, 2026
zackees added a commit that referenced this pull request Jun 7, 2026
…dies on FASTLED_LOG_RUNTIME_ENABLED (#2918)

Closes #2917.

Wraps the bodies of the two `FL_NO_INLINE` cold-path emit helpers in
`fl::ChannelEngineRMTImpl` with `#if FASTLED_LOG_RUNTIME_ENABLED`. In
release builds (NDEBUG → `FASTLED_LOG_VERBOSITY=0` per Stage 1) the
helpers collapse to ~5 B function bodies (parameters cast to `(void)`,
single `ret`), down from ~410-418 B each.

## Why the existing FL_NO_INLINE + FL_WARN pattern wasn't enough

```cpp
FL_NO_INLINE void emitRecoveryWarning(...) FL_NOEXCEPT {
    fl::sstream msg;                          // [1] constructed unconditionally
    msg << "..." << ... << external_words;    // [2] 15 operator<< calls fire
    FL_WARN(msg.str());                       // [3] expands to no-op in release
}
```

In release builds:
- `FL_WARN(X)` expands to `do { if (false) { ... << X; } } while(0)` —
  optimizer DCEs the inner block (`msg.str()` call elided).
- But `fl::sstream msg;` at [1] and `msg << ...` at [2] are **outside**
  the `if (false)` block. They have observable side effects on `msg`'s
  internal buffer (heap allocation, sequential writes), so the optimizer
  keeps the constructor + all 15 `operator<<` calls live in the function
  body.

Result: the FL_NO_INLINE pulled the diagnostic chain out of the
function it was hoisted from (`createChannel`) — into its own symbol
— but the bytes stayed in the binary.

## Measured baseline (post-#2916 ELF, `master @ 5ca722e`)

| Symbol | Size |
|---|---:|
| `fl::ChannelEngineRMTImpl::emitAllocationFailureError` (`$isra$0`) | 418 B |
| `fl::ChannelEngineRMTImpl::emitRecoveryWarning` (`$isra$0`) | 410 B |
| **Total in scope** | **~828 B** |

Both symbols collapse to ~5 B after this PR.

## Behavior preserved

- **Debug builds (`FASTLED_LOG_VERBOSITY=1`, default for non-NDEBUG):**
  the diagnostic emits exactly as before. Users debugging RMT
  allocation failures still see the multi-line action-required
  message.
- **Release builds (`FASTLED_LOG_VERBOSITY=0`, NDEBUG default since
  #2890):** the helper bodies become empty; the callers in
  `attemptAllocationRecovery` still call them (the call overhead is
  ~5 B / site), but the bodies cost nothing.

The FL_WARN macro itself was always a no-op in release; this PR makes
the body that *built the message* match the macro's release-build
behavior.

## Other emit helpers — audit notes

- `attemptAllocationRecovery` (315 B total): contains its own FL_WARN
  and FL_LOG_RMT calls plus actual retry-loop arithmetic. The
  diagnostic calls go through the standard `FL_WARN` macro which is
  already `do { if (false) { ... } } while(0)` in release — the
  optimizer DCEs the inline chain. The 315 B is the retry-loop body
  + `Rmt5ChannelConfig retry_config(...)` construction; NOT the
  diagnostic emission. Leaving as-is.
- `handleAllocateTxFailure` (63 B): already a `FL_NO_INLINE` cold
  helper at 63 B post-Stage-1 — almost entirely the fallback retry
  body. No further gating needed.

## Out of scope

- Removing the FL_WARN calls from the source. They're useful in debug
  builds; the gate keeps them debug-build-active.
- Auditing every FL_WARN call site in the RMT5 driver — the inline
  ones inside hot function bodies are already collapsed correctly by
  the `if (false)` DCE.

## Verification

- `bash lint --cpp` → all C++ linting checks pass.
- Behavior preserved by construction: the gate is on a build-time
  define that defaults to "diagnostics on" in debug builds.
- Measured saving validated on this PR's CI run via the Stage 6
  regression gate. Expected: `total_flash` drops by ~700-800 B from
  the current baseline of `347,004 B`. A follow-up commit ratchets
  the baseline file in the same PR.

Refs #2886, #2917, #2908, #2911, #2914.
zackees added a commit that referenced this pull request Jun 7, 2026
…nd FASTLED_DISABLE_UCS7604 (#2921)

Closes #2920.

Mirrors the pattern shipped in #2914 (SPI dispatch gate). For
WS2812-only sketches the UCS7604 cases in the clockless switch in
`fl::Channel::showPixels` are dynamically unreachable, but the
`writeUCS7604(...)` reference inside is statically reachable, keeping
the encoder bodies linked. Setting `-DFASTLED_DISABLE_UCS7604=1`
removes the case at preprocess time and lets the linker dead-strip
the encoder templates plus the wrapper.

## Measured baseline (post-#2918 ELF, master @ ded5eea)

UCS7604-only symbols currently linked into NEOPIXEL Blink:

| Symbol | Size |
|---|---:|
| fl::encodeUCS7604_16bit_RGBW<ScaledPixelIteratorRGBW, ...> | 184 B |
| fl::encodeUCS7604_16bit_RGB<ScaledPixelIteratorRGB, ...>   | 152 B |
| writeUCS7604(...) wrapper (anon-ns, size est.)             | ~100-200 B |
| **Estimated total**                                        | **~400-500 B** |

Plus the inline switch-case footprint (3 case labels + dispatch).

Projected saving with the flag set: **~400-600 B** on NEOPIXEL Blink.

## Behavior

- Flag unset (default): No change.
- Flag set: UCS7604 cases removed; calling showPixels() on a UCS7604
  channel silently emits nothing. User opts in with the understanding
  that they're not using UCS7604.

## Files

- src/fl/channels/channel.cpp.hpp — wraps the UCS7604 cases in
  `#if !defined(FASTLED_DISABLE_UCS7604) || !FASTLED_DISABLE_UCS7604`.
  The gate's rationale documented inline.
- docs/SLIM_ESP32S3.md — adds row 7 to the priority table.

## Verification

- bash lint --cpp -> all C++ linting checks pass.
- Default behavior unchanged; regression-gate baseline unaffected.

Refs #2886, #2920, #2914, #2918.
zackees added a commit that referenced this pull request Jun 7, 2026
…ABLE_DYNAMIC_DRIVER (#2927)

Closes #2926.

Adds opt-in build flag `FASTLED_DISABLE_DYNAMIC_DRIVER=1` that gates
out `Channel::resolveDynamicDriver()`. For every legacy `addLeds<>`
flavor (including `addLeds<NEOPIXEL>` -> ClocklessIdf5), `mDriverPreBound`
is true after ctor and the else branch in `Channel::showPixels` is
dead at runtime — but the compiler can't prove it, so the linker
keeps the call chain (`resolveDynamicDriver` + `ChannelManager::
findDriverByName` + `selectDriverForChannel`) live.

Mirrors the pattern from #2914 (SPI gate) and #2921 (UCS7604 gate):
opt-in build flag, no default behavior change, projected ~400-900 B
on stock NEOPIXEL Blink with the flag set.

## Behavior

- **Flag unset (default):** No change. Dynamic-driver lookup runs as
  before for channels created via `Channel::create(cfg)` without
  pre-binding.
- **Flag set:**
  - `addLeds<NEOPIXEL>` / `addLeds<...>` flow: unchanged. They
    pre-bind their driver in the ctor.
  - `Channel::create(cfg)` without pre-binding: `showPixels()` returns
    silently. User accepts the constraint by setting the flag.

## Files

- `src/fl/channels/channel.cpp.hpp`:
  - `Channel::showPixels` else branch wrapped in `#if !defined(FASTLED_DISABLE_DYNAMIC_DRIVER) || !FASTLED_DISABLE_DYNAMIC_DRIVER`.
  - `Channel::resolveDynamicDriver` body excluded when the flag is set
    (returns empty shared_ptr). Lets the linker dead-strip the
    `findDriverByName` / `selectDriverForChannel` chain.
- `docs/SLIM_ESP32S3.md`: row 8 added to the priority table.

## Verification

- `bash lint --cpp` -> all C++ linting checks pass.
- Default behavior unchanged; regression-gate baseline unaffected.

## Expected savings

Projected ~400-900 B on stock NEOPIXEL Blink with the flag set.
Dead-strip cascade may push it higher (see #2918 and #2925 precedents
where collapsing one cold-path symbol cascaded into 3-4x the
single-symbol projection).

Refs #2886, #2926, #2914, #2918, #2921, #2925.
zackees added a commit that referenced this pull request Jun 7, 2026
…_EVENTS (#2932)

Closes #2931.

Adds opt-in build flag `FASTLED_DISABLE_CHANNEL_EVENTS=1` that
replaces `fl::ChannelEvents`'s 7 `fl::function_list<...>` event-slot
members with a no-op fallback (`detail::NoOpChannelEvent`) that
accepts `operator()(Args&&...)`, `add(F, priority=0)`, and `remove(id)`
but does nothing. The 18 internal call sites across `src/` need no
changes — `events.onChannelXxx(args)` resolves to the no-op at
compile time.

Mirrors the opt-in pattern from #2914 / #2921 / #2927.

## Why this is a win

`fl::ChannelEvents::ChannelEvents()` ctor is 395 B (×2 C1+C2 = 790 B)
in the post-#2929 baseline. The ctor initializes 7 unique
`fl::function_list<...>` template instantiations, each of which pulls
its own storage, iteration, and `call()` machinery. For stock
`addLeds<NEOPIXEL>` sketches with no registered callbacks, every
event-fire (e.g. `events.onChannelDataEncoded(...)` from every
`Channel::showPixels` frame) is a no-op iteration over an empty list
— but the linker keeps all the supporting machinery alive.

Replacing the slots with a single `NoOpChannelEvent` type drops the
ctor body, the 7 unique `fl::function_list` instantiations, and the
`fl::Singleton<ChannelEvents>::instance()` chain. Projected ~1-2 KB
on stock NEOPIXEL Blink with the flag set.

## Behavior

| Flag | Code path | User registers callback | Behavior |
|---|---|---|---|
| unset (default) | real `fl::function_list` | yes | Callback fires as expected. |
| unset (default) | real `fl::function_list` | no | call() iterates empty list. |
| set | `detail::NoOpChannelEvent` | yes | Registration compiles (returns -1) but never fires. |
| set | `detail::NoOpChannelEvent` | no | Same as default — nothing happens. |

## Files

- src/fl/channels/channel_events.h: add `#if FASTLED_DISABLE_CHANNEL_EVENTS`
  branch with the no-op fallback class. Keep the original full
  implementation under `#else`.
- src/fl/channels/channel_events.cpp.hpp: gate the out-of-line
  `instance()` definition so the inline header version in the no-op
  branch is the only definition.
- docs/SLIM_ESP32S3.md: row 9 added to the priority table.

## Verification

- bash lint --cpp -> all C++ linting checks pass.
- Default behavior unchanged; regression-gate baseline unaffected.

## Expected savings

Projected ~1-2 KB on stock NEOPIXEL Blink with the flag set. The
dead-strip cascade hypothesis (per #2918 / #2925 / #2929) suggests
the actual saving may exceed projection.

Refs #2886, #2931, #2914, #2921, #2927, #2929.
zackees added a commit that referenced this pull request Jun 7, 2026
…max_savings (#2934)

Closes #2933.

Adds coverage for the four opt-in build flags shipped after #2906:

- `FASTLED_DISABLE_SPI_CHIPSETS=1` (#2914) — disable_spi config
- `FASTLED_DISABLE_UCS7604=1` (#2921) — disable_ucs7604 config
- `FASTLED_DISABLE_DYNAMIC_DRIVER=1` (#2927) — disable_dyndriver config
- `FASTLED_DISABLE_CHANNEL_EVENTS=1` (#2932) — disable_events config

Plus a new `max_savings` config that stacks ALL eight opt-ins
(Stages 2 + 3 + 4 + the 4 new gates) — the headline cumulative
saving for users who enable everything.

Also adds a `slim_row` field to `OptInConfig` and a new `SLIM row`
column to the comparison table. The output table now maps 1:1 onto
the priority table in `docs/SLIM_ESP32S3.md`, making it
copy-pasteable into a follow-up doc-flip PR.

## Files

- `tests/measure_esp32s3_opt_ins.py`:
  - `OptInConfig` gains `slim_row: int | None`.
  - New module-level `_ALL_OPT_IN_FLAGS` tuple so the `max_savings`
    config doesn't drift from the per-flag configs.
  - 4 new configs + `max_savings` added to `CONFIGS`.
  - `format_table` gains the `SLIM row` column.

## Verification

- `bash lint` -> all linters pass (ruff, ty, C++, JS setup).
- No FastLED runtime change; doesn't affect any build.
- The config matrix matches the SLIM doc priority table 1:1.

## Out of scope

- Running the measurements. Separate follow-up PR.
- Updating SLIM doc rows 📊 → ✅. Requires the measurements.

Refs #2886, #2906, #2914, #2921, #2927, #2932.
@zackees
zackees deleted the feat/2913-disable-spi-chipsets branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

1 participant