Skip to content

Gate Channel::resolveDynamicDriver behind FASTLED_DISABLE_DYNAMIC_DRIVER (~400-900 B) (#2886) #2926

Closed

Description

@zackees

Goal

Gate Channel::resolveDynamicDriver() behind an opt-in FASTLED_DISABLE_DYNAMIC_DRIVER=1 build flag, with Channel::showPixels shortcut-returning silently if the driver isn't pre-bound. For stock addLeds<NEOPIXEL> (and every other addLeds<> flavor that calls setDriver(...) in its ctor), the dynamic-driver-lookup path is dead at runtime — but it's statically reachable from showPixels, so the 373 B is pinned in the binary.

Parent: #2886 — eleventh algorithmic-bloat reduction (after sort_small, s16x16::pow, emit-gate, SPI gate, UCS7604 gate, assert-gate, plus the doc/Stage PRs).

Why this is concrete

fl::Channel::showPixels at src/fl/channels/channel.cpp.hpp:459-471:

if (mDriverPreBound) {
    driver = mDriver.lock();
    if (!driver) { return; }
} else {
    driver = resolveDynamicDriver();  // [link target]
    if (!driver) { return; }
}

mDriverPreBound is set to true by ClocklessIdf5::ClocklessIdf5()'s setDriver(BusTraits<Bus::RMT>::instancePtr()) call. The else branch is dead at runtime for the legacy addLeds<> flow. But the compiler can't prove the runtime value of mDriverPreBound, so it keeps the resolveDynamicDriver() call statically reachable.

Measured baseline (post-#2925 ELF, master @ f8ca3aa715)

Symbol Size
fl::Channel::resolveDynamicDriver() 373 B
fl::ChannelManager::findDriverByName(...) (only called from resolveDynamicDriver in this build) ~100-200 B est.
fl::ChannelManager::selectDriverForChannel(...) (same caller) ~150-300 B est.
Estimated total ~600-900 B

The dead-strip cascade pattern from #2918 and #2925 suggests the actual saving may exceed the headline 373 B once the ChannelManager lookup chain dead-strips with no live caller.

Deliverable

src/fl/channels/channel.cpp.hpp — gate the call site

 if (mDriverPreBound) {
     driver = mDriver.lock();
     if (!driver) { return; }
 } else {
+#if !defined(FASTLED_DISABLE_DYNAMIC_DRIVER) || !FASTLED_DISABLE_DYNAMIC_DRIVER
     driver = resolveDynamicDriver();
     if (!driver) { return; }
+#else
+    // Dynamic-driver lookup gated out via FASTLED_DISABLE_DYNAMIC_DRIVER
+    // (#2926). Channels created via Channel::create(cfg) without a
+    // pre-bound driver silently emit nothing when this flag is set.
+    return;
+#endif
 }

Also gate resolveDynamicDriver()'s definition itself so the body is excluded from compilation when the flag is set — that's what allows the linker to dead-strip ChannelManager::findDriverByName / selectDriverForChannel.

Behavior when the flag is set

  • addLeds<NEOPIXEL> (and every legacy addLeds<> flavor): unchanged. They pre-bind in their ctors.
  • Channel::create(cfg) (manager-based API without pre-binding): showPixels returns silently. User accepts the constraint by setting the flag.

Documentation

  • docs/SLIM_ESP32S3.md priority table gains row 9 with the new flag.
  • agents/docs/binary-size-analysis.md mirrors.

Acceptance

  1. FASTLED_DISABLE_DYNAMIC_DRIVER=1 build flag gates resolveDynamicDriver().
  2. bash lint --cpp passes.
  3. Default behavior unchanged.
  4. Measured saving: projected ~400-900 B on stock NEOPIXEL Blink with the flag set.
  5. docs/SLIM_ESP32S3.md row 9 exists.

Out of scope

Related

🤖 Generated with Claude Code

Activity

  1. added a commit that references this issue on Jun 7, 2026
    d03798a
  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