Skip to content

perf(channels): gate Channel::resolveDynamicDriver behind FASTLED_DISABLE_DYNAMIC_DRIVER - #2927

Merged
zackees merged 1 commit into
masterfrom
feat/2926-disable-dynamic-driver
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2926-disable-dynamic-driver

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

Closes #2926. Opt-in build flag drops the dynamic-driver lookup chain on stock NEOPIXEL Blink (~400-900 B projected). Mirrors #2914 / #2921 pattern.

Refs #2886, #2914, #2918, #2921, #2925.

Summary by CodeRabbit

  • New Features

    • Introduced optional build configuration to reduce memory footprint on resource-constrained embedded devices, enabling deployments with limited flash storage.
  • Documentation

    • Updated optimization documentation to include new memory-saving configuration option, with guidance on behavioral constraints for channel initialization when dynamic resolution is disabled.

…ABLE_DYNAMIC_DRIVER

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
zackees merged commit d03798a 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: d224d526-2781-45a4-a15a-4aa51f72e175

📥 Commits

Reviewing files that changed from the base of the PR and between f8ca3aa and c69ce69.

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

📝 Walkthrough

Walkthrough

This PR adds a new opt-in compile-time flag FASTLED_DISABLE_DYNAMIC_DRIVER to gate out dynamic driver resolution code from FastLED builds. The implementation conditionally compiles out Channel::resolveDynamicDriver() and its call in Channel::showPixels(), enabling linker dead-stripping. The documentation describes the flag's behavior and constraints for manager-created channels without pre-binding.

Changes

Dynamic Driver Opt-Out Feature

Layer / File(s) Summary
Dynamic driver resolution gating and documentation
src/fl/channels/channel.cpp.hpp, docs/SLIM_ESP32S3.md
Channel::resolveDynamicDriver() gains conditional compilation that returns empty when FASTLED_DISABLE_DYNAMIC_DRIVER is enabled; Channel::showPixels() wraps the driver resolution call in the same guard, causing non-prebound channels to return early without emission when dynamic drivers are disabled; new table entry documents the flag, its gating behavior, and usage constraints.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • FastLED/FastLED#2926: Directly related — both changes gate Channel::resolveDynamicDriver() and showPixels dynamic-driver path behind FASTLED_DISABLE_DYNAMIC_DRIVER with identical code-level modifications.
  • FastLED/FastLED#2920: Related — both modify Channel::showPixels() to conditionally compile out specific runtime dispatch paths using opt-in FASTLED_DISABLE_* flags for size optimization.
  • FastLED/FastLED#2428: Related — both touch driver-resolution paths in Channel to enable compile-time/no-runtime-driver builds via conditional compilation.

Possibly related PRs

  • FastLED/FastLED#2851: Overlaps in Channel::showPixels() — this PR gates out resolveDynamicDriver() and alters non-prebound behavior, while the referenced PR refactors the disabled-driver warning emission logic in the same function.
  • FastLED/FastLED#2441: Both modify Channel::showPixels() to change driver-resolution behavior via different compile-time conditions, directly connected around the same driver-selection path.
  • FastLED/FastLED#2795: Both modify Channel::showPixels() post-resolution behavior — this PR compiles out resolveDynamicDriver() and early-returns when dynamic drivers are disabled; the referenced PR adds a guard to early-return when the resolved driver is DISABLED.

Poem

A rabbit hops with glee,
Trimming drivers for efficiency!
When dynamic calls are barred away,
Flash is saved—hip hip hooray! 🐰

✨ 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/2926-disable-dynamic-driver

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
…_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/2926-disable-dynamic-driver 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 Channel::resolveDynamicDriver behind FASTLED_DISABLE_DYNAMIC_DRIVER (~400-900 B) (#2886)

1 participant