Repository navigation
perf(esp32): gate SPI dispatch in Channel::showPixels behind FASTLED_DISABLE_SPI_CHIPSETS - #2914
Conversation
…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.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR implements the ChangesSPI Chipset Encoding Compile-Time Gate
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
…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.
…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.
…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.
…_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.
…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.
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=1that gatesthe SPI dispatch branch in
fl::Channel::showPixels. For NEOPIXEL-onlysketches the SPI branch is dynamically unreachable, but the compiler
cannot prove that — every
pixelIterator.writeXXX(...)referenceinside 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:
fl::PixelIterator::writeLPD8806<fl::vector_psram<u8>>fl::PixelIterator::writeSK9822<fl::vector_psram<u8>>fl::PixelIterator::writeAPA102<fl::vector_psram<u8>>fl::PixelIterator::writeSM16716<fl::vector_psram<u8>>Plus the
showPixelsbody 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
every existing example using APA102 / SK9822 / etc. continues to
work.
-DFASTLED_DISABLE_SPI_CHIPSETS=1): The SPI branch isremoved at preprocess time.
showPixels()on a channel whosechipset is an
SpiChipsetConfigfalls through to the post-dispatchevent 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_CHIPSETSwraps the
else if (mChipset.is<SpiChipsetConfig>())block. Thegate's behavior + savings are documented inline at the comment block
above the branch.
docs/SLIM_ESP32S3.md— adds row 6 to the "Release-build flashsavers" priority table with the new flag, its constraint, and PR
link.
Verification
bash lint --cpp→ all C++ linting checks pass.unchanged.
-DFASTLED_DISABLE_SPI_CHIPSETS=1build of Blink, compared againstthe current
347,004 Bbaseline).Expected savings
(235 B), writeSM16716 (91 B) = 720 B (PixelIterator SPI encoders
reachable only from showPixels' SPI branch).
showPixelsbody.The Stage 6 regression gate (
tests/test_esp32s3_bloat_regression.py,baseline =
347004) does NOT change in this PR because it measuresthe 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
New Features