Repository navigation
Description
Goal
Gate fl::ChannelEvents (and all 18 of its event-firing call sites across src/) behind an opt-in FASTLED_DISABLE_CHANNEL_EVENTS=1 build flag. For stock addLeds<NEOPIXEL> sketches that don't register any callbacks (the common case), the entire event-dispatch infrastructure is dead at runtime — but the linker keeps the ChannelEvents ctor + 7 fl::function_list<...> template instantiations + per-call-site instance() access alive.
Parent: #2886 — thirteenth algorithmic-bloat reduction. Tactical opt-in (default-flag baseline unchanged).
Why this is a real win
fl::ChannelEvents at src/fl/channels/channel_events.h:42 holds 7 fl::function_list<void(...)> member fields:
struct ChannelEvents {
static ChannelEvents& instance();
fl::function_list<void(const IChannel&)> onChannelCreated;
fl::function_list<void(const IChannel&)> onChannelBeginDestroy;
fl::function_list<void(const IChannel&)> onChannelAdded;
fl::function_list<void(const IChannel&)> onChannelRemoved;
fl::function_list<void(const IChannel&, const ChannelConfig&)> onChannelConfigured;
fl::function_list<void(const IChannel&, const ChannelData&)> onChannelDataEncoded;
fl::function_list<void(const IChannel&, const fl::string& driverName)> onChannelEnqueued;
};The ctor at 395 B × 2 = 790 B initializes all 7 members. For each unique callback signature, fl::function_list instantiates its template machinery (storage, iteration, call()).
events.onChannelDataEncoded(*this, *mChannelData) fires every frame from Channel::showPixels — even when no callbacks are registered. At runtime it's a no-op iteration over an empty list, but the call() method body for each unique signature is linked.
Measured baseline (post-#2929 ELF, master @ d9c0b66108)
| Symbol | Size |
|---|---|
fl::ChannelEvents::ChannelEvents() (C1+C2 copies) |
395 + 395 = 790 B |
7× per-signature fl::function_list::call() instantiations |
est. ~150-250 B each |
18× ChannelEvents::instance() + event-fire call-site bytes |
est. ~200-400 B total |
| Estimated total | ~1-2 KB |
Deliverable
Mechanism
src/fl/channels/channel_events.h adds an inline no-op fallback class when FASTLED_DISABLE_CHANNEL_EVENTS is set:
#if defined(FASTLED_DISABLE_CHANNEL_EVENTS) && FASTLED_DISABLE_CHANNEL_EVENTS
// All event fires expand to no-ops via the empty inline ChannelEvents
// struct. No fl::function_list member instantiations.
struct ChannelEvents {
static ChannelEvents& instance() FL_NOEXCEPT {
static ChannelEvents s; return s;
}
// Each member is a callable that accepts any args and does nothing.
struct NoOpCallback {
template <typename... Args>
void operator()(Args&&...) const FL_NOEXCEPT {}
};
NoOpCallback onChannelCreated;
NoOpCallback onChannelBeginDestroy;
NoOpCallback onChannelAdded;
NoOpCallback onChannelRemoved;
NoOpCallback onChannelConfigured;
NoOpCallback onChannelDataEncoded;
NoOpCallback onChannelEnqueued;
};
#else
// Real implementation with fl::function_list members.
struct ChannelEvents { /* ... existing ... */ };
#endifThe 18 call sites stay unchanged. events.onChannelDataEncoded(*this, *mChannelData) resolves to either:
- The real
fl::function_list<void(const IChannel&, const ChannelData&)>::operator()(default), or - The no-op
NoOpCallback::operator()<Args...>(with the flag set).
No call-site touches needed.
Behavior matrix
| Flag | Code path | User registers callback | Behavior |
|---|---|---|---|
| unset | real | yes | Callback fires as expected. |
| unset | real | no | call() iterates empty list, returns. |
| set | no-op | yes | Callback registration is a no-op; never fires. |
| set | no-op | no | Same as default — nothing happens. |
The behavioral change for users who set the flag AND register callbacks: their callbacks never fire. This is the documented constraint.
Documentation
docs/SLIM_ESP32S3.mdpriority table gains row 9.agents/docs/binary-size-analysis.mdmirrors.
Acceptance
FASTLED_DISABLE_CHANNEL_EVENTS=1build flag gates the class.bash lint --cpppasses.- Default behavior unchanged.
- Measured saving: projected ~1-2 KB on stock NEOPIXEL Blink with the flag set.
docs/SLIM_ESP32S3.mdrow 9 exists.
Out of scope
- Removing event firing call sites permanently. Users who don't want events but also won't set the flag get the current behavior.
- Splitting into per-event flags (
FASTLED_DISABLE_ON_CHANNEL_DATA_ENCODEDetc.). All 7 are gated together.
Related
- Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886 — parent meta + audit cycle.
- perf(esp32): gate SPI dispatch in Channel::showPixels behind FASTLED_DISABLE_SPI_CHIPSETS #2914 / perf(esp32): gate UCS7604 clockless cases in Channel::showPixels behind FASTLED_DISABLE_UCS7604 #2921 / perf(channels): gate Channel::resolveDynamicDriver behind FASTLED_DISABLE_DYNAMIC_DRIVER #2927 — prior opt-in build-flag gates (the pattern this mirrors).
- perf(gamma): simplify Gamma8::getOrCreate to single-entry weak_ptr cache #2929 — gamma cache simplification (same dead-strip cascade hypothesis).
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
perf(channels): gate fl::ChannelEvents behind FASTLED_DISABLE_CHANNEL…