Skip to content

perf(channels): gate fl::ChannelEvents behind FASTLED_DISABLE_CHANNEL_EVENTS - #2932

Merged
zackees merged 1 commit into
masterfrom
feat/2931-disable-channel-events
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2931-disable-channel-events

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

Closes #2931. Opt-in build flag replaces 7 fl::function_list event slots with NoOpChannelEvent. Projected ~1-2 KB on stock NEOPIXEL Blink. Refs #2886.

Summary by CodeRabbit

  • New Features

    • Added optional -DFASTLED_DISABLE_CHANNEL_EVENTS=1 build flag to reduce flash memory usage (~1-2 KB) on memory-constrained devices. When enabled, channel event listeners compile but callbacks are silently skipped.
  • Documentation

    • Updated ESP32S3 optimization guide with new memory-saving build option.

…_EVENTS

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
zackees merged commit 9dd82cf into master Jun 7, 2026
@fastled-project-sync fastled-project-sync Bot moved this to Triage 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: 5d1836fc-d89f-4d3c-b8ad-2c4945884271

📥 Commits

Reviewing files that changed from the base of the PR and between d9c0b66 and fe20aba.

📒 Files selected for processing (3)
  • docs/SLIM_ESP32S3.md
  • src/fl/channels/channel_events.cpp.hpp
  • src/fl/channels/channel_events.h

📝 Walkthrough

Walkthrough

This PR implements an opt-in build flag FASTLED_DISABLE_CHANNEL_EVENTS that gates the entire channel event system, replacing it with no-op implementations to eliminate ~1–2 KB of dead code for sketches that don't register event callbacks.

Changes

Channel Events Conditional Compilation

Layer / File(s) Summary
No-op event implementation and header conditional structure
src/fl/channels/channel_events.h
Adds fl/stl/noexcept.h include and introduces detail::NoOpChannelEvent (a callable struct with no-op operator(), add() returning -1, and no-op remove()). The original ChannelEvents definition with fl::function_list<...> members is wrapped in #else, and the entire conditional block is closed with #endif.
Singleton instantiation gating
src/fl/channels/channel_events.cpp.hpp
Wraps the out-of-line ChannelEvents::instance() definition in #if !defined(FASTLED_DISABLE_CHANNEL_EVENTS) || !FASTLED_DISABLE_CHANNEL_EVENTS so the singleton and its template machinery are not instantiated when the flag is enabled, allowing link-time garbage collection via --gc-sections.
Build flag documentation
docs/SLIM_ESP32S3.md
Adds a row to the "Release-build flash savers" table documenting the new -DFASTLED_DISABLE_CHANNEL_EVENTS=1 flag, its ~1–2 KB size impact, and the constraint that user-registered callbacks are compiled but silently dropped.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • FastLED/FastLED#2435: Also modifies src/fl/channels/channel_events.h to change callback parameter types from Channel& to IChannel& in the onChannel* listener declarations, overlapping with this PR's conditional member type changes.

Poem

🐰 A flag to trim the bloat away,
No callbacks firing every day,
Just silent no-ops, lean and bright,
Two kilobytes of precious light. ✨

✨ 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/2931-disable-channel-events

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 from Triage to Done in FastLED Tracker Jun 7, 2026
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/2931-disable-channel-events 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 fl::ChannelEvents behind FASTLED_DISABLE_CHANNEL_EVENTS (~1-2 KB) (#2886)

1 participant