Skip to content

Gate fl::ChannelEvents behind FASTLED_DISABLE_CHANNEL_EVENTS (~1-2 KB) (#2886) #2931

Closed

Description

@zackees

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 ... */ };
#endif

The 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.md priority table gains row 9.
  • agents/docs/binary-size-analysis.md mirrors.

Acceptance

  1. FASTLED_DISABLE_CHANNEL_EVENTS=1 build flag gates the class.
  2. bash lint --cpp passes.
  3. Default behavior unchanged.
  4. Measured saving: projected ~1-2 KB on stock NEOPIXEL Blink with the flag set.
  5. docs/SLIM_ESP32S3.md row 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_ENCODED etc.). All 7 are gated together.

Related

🤖 Generated with Claude Code

Activity

  1. added a commit that references this issue on Jun 7, 2026
    9dd82cf
  2. moved this from Triage to Done in FastLED Trackeron Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions