Skip to content

perf(esp32): gate UCS7604 clockless cases in Channel::showPixels behind FASTLED_DISABLE_UCS7604 - #2921

Merged
zackees merged 1 commit into
masterfrom
feat/2920-disable-ucs7604
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2920-disable-ucs7604

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

Closes #2920. Mirrors #2914's SPI dispatch gate for the UCS7604 clockless cases. Opt-in build flag drops ~400-600 B on WS2812-only NEOPIXEL Blink builds. Default behavior unchanged; regression-gate baseline unaffected.

Summary by CodeRabbit

  • New Features

    • Added optional compile-time flag to reduce flash memory usage by disabling UCS7604 LED support.
  • Documentation

    • Updated build options guide with new flash-saving configuration flag and its constraints.

…nd FASTLED_DISABLE_UCS7604

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
zackees merged commit 9f9abd9 into master Jun 7, 2026
@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
@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: 14dc6cc2-5026-4efe-a2e7-0abf1e968844

📥 Commits

Reviewing files that changed from the base of the PR and between ded5eea and a2a8bca.

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

📝 Walkthrough

Walkthrough

This PR gates UCS7604 encoder handling in Channel::showPixels() behind an opt-in compile-time flag FASTLED_DISABLE_UCS7604=1, allowing linker dead-stripping of ~400–600 B of encoder template instantiations for WS2812-only sketches. The flag implementation and corresponding documentation are added together.

Changes

UCS7604 encoder gating

Layer / File(s) Summary
UCS7604 encoder gating and documentation
src/fl/channels/channel.cpp.hpp, docs/SLIM_ESP32S3.md
UCS7604 encoder case statements (CLOCKLESS_ENCODER_UCS7604_8BIT, ..._16BIT, ..._16BIT_1600) and the writeUCS7604() dispatch are wrapped in #if !defined(FASTLED_DISABLE_UCS7604) || !FASTLED_DISABLE_UCS7604 to exclude them when the flag is set. Documentation row 7 is added to the flash-savers table documenting the flag, its projected savings, and the constraint that UCS7604 output falls silent if both the flag and FastLED.addLeds<UCS7604, ...> are used.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

  • #2920 — The linked issue whose objectives are directly addressed by this PR: gate UCS7604 clockless cases behind FASTLED_DISABLE_UCS7604 flag.
  • #2886 — Parent meta-issue for the audit cycle that includes UCS7604 gating as a tactical optimization.
  • #2913 — Related SPI dispatch gating pattern (FASTLED_DISABLE_SPI) applied to a different encoder type in the same showPixels() dispatch.
  • #2914 — Prior implementation of SPI chipset dispatch gating, establishing the pattern for compile-time encoder case exclusion.
  • #2901 — Related discussion of Stage-4 algorithmic bloat reduction in Channel::showPixels().

Poem

A gate for UCS7604 appears, 🐰
Four hundred bytes drop off with cheers,
When WS2812 alone you'd use,
Flash shrinks with just a compile fuse—
Quick wins for sketches ever tight! 🐇✨

✨ 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/2920-disable-ucs7604

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.

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/2920-disable-ucs7604 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.

Gate UCS7604 clockless cases in Channel::showPixels behind FASTLED_DISABLE_UCS7604 (~500 B) (#2886)

1 participant