Skip to content

Gate resolveDynamicDriver bus-miss diagnostic probe in release builds #2952

Closed

Description

@zackees

Goal

Gate the bus-miss diagnostic probe in `fl::Channel::resolveDynamicDriver` (`src/fl/channels/channel.cpp.hpp:414-438`) on `FASTLED_LOG_RUNTIME_ENABLED` so the diagnostic-only `findDriverByName(busKey)` probe + string-comparison + empty FL_ERROR setup dead-strip from release builds.

Parent: #2886 — tactical bloat win, same dead-strip cascade pattern as #2918 / #2925 / #2943.

Why this is a real win

`resolveDynamicDriver()` runs on every frame for channels that don't pre-bind a driver. The post-lookup diagnostic block at `channel.cpp.hpp:414-438`:

```cpp
if (mBus != Bus::AUTO && !mBusWarned &&
(!driver || driver->getName() != busKey)) {
auto busDriver = ChannelManager::instance().findDriverByName(busKey);
if (!busDriver) {
FL_ERROR("Channel '" << mName << "': Driver '" << busKey
<< "' wasn't instantiated. Resolve with: ...");
} else {
FL_ERROR("Channel '" << mName << "': Driver '" << busKey
<< "' is registered but cannot handle this channel's chipset ...");
}
mBusWarned = true;
}
if (!driver) {
FL_ERROR("Channel '" << mName << "': No compatible driver found - cannot transmit");
}
```

In release builds (NDEBUG → `FASTLED_LOG_VERBOSITY=0` per #2890) every `FL_ERROR` body collapses to `do {} while(0)`, but the surrounding code still runs:

  • `driver->getName()` virtual call + `fl::string != fl::string` comparison (the per-frame branch test that selects "silent miss vs.diagnosed miss").
  • `ChannelManager::instance().findDriverByName(busKey)` — a silent-on-miss probe that exists ONLY to differentiate between "driver not instantiated" and "driver rejected canHandle()" in the diagnostic message.
  • `mBusWarned` reads/writes.
  • The empty `if (!driver) {}` test at the end.

None of those operations affect runtime behavior in release — they only feed the diagnostic message that no longer renders.

Deliverable

`src/fl/channels/channel.cpp.hpp:414-438` — gate the diagnostic block

```cpp
fl::shared_ptr driver =
ChannelManager::instance().selectDriverForChannel(mChannelData, busKey);
mDriver = driver;

#if FASTLED_LOG_RUNTIME_ENABLED
if (mBus != Bus::AUTO && !mBusWarned &&
(!driver || driver->getName() != busKey)) {
auto busDriver = ChannelManager::instance().findDriverByName(busKey);
if (!busDriver) {
FL_ERROR("Channel '" << mName << "': Driver '" << busKey
<< "' wasn't instantiated. Resolve with: "
<< "(1) fl::enableDrivers<fl::Bus::" << busKey << ">() "
<< "(links only this driver), "
<< "(2) FastLED.enableAllDrivers() (links every driver), or "
<< "(3) FastLED.addLeds<..., fl::Bus::" << busKey << ">(...) "
<< "(legacy API; pins Bus + triggers linker keep-alive). "
<< "Defaulting to AUTO/priority dispatch.");
} else {
FL_ERROR("Channel '" << mName << "': Driver '" << busKey
<< "' is registered but cannot handle this channel's chipset "
<< "(bus/chipset mismatch). Defaulting to AUTO/priority dispatch.");
}
mBusWarned = true;
}
if (!driver) {
FL_ERROR("Channel '" << mName << "': No compatible driver found - cannot transmit");
}
#endif
return driver;
```

Behavior matrix

Build Bus Driver registered? Behaviour
Debug typed no One-shot FL_ERROR with remediation hint
Debug typed yes (canHandle=no) One-shot FL_ERROR with bus/chipset mismatch hint
Debug AUTO n/a Silent (no diagnostic ever)
Release typed no Silently falls through to nullptr; caller's `if (!driver) return;` skips the frame.
Release typed yes (canHandle=no) Same as above.
Release AUTO n/a Same as debug.

The functional return value (`fl::shared_ptr driver`) is preserved unconditionally in both builds. Only the diagnostic side-effect is gated.

Acceptance

  1. `bash lint --cpp` passes.
  2. Behaviour preserved in debug builds.
  3. `bloat regression esp32s3` on the PR passes (any positive saving lowers `tests/data/esp32s3_bloat_baseline.txt` in a follow-up ratchet).

Expected savings

Projected ~150-600 B. The cascade could exceed projection if `findDriverByName`'s remaining callers (`ChannelManager::getDriverByName`, `ChannelManager::selectDriverForChannel`) also get `-DFASTLED_DISABLE_DYNAMIC_DRIVER=1`'d in default release — but #2926's gate is opt-in not default, so the dead-strip cascade likely won't trigger here. Realistic savings: ~150-300 B from the empty FL_ERROR bodies + the per-frame branch test + `mBusWarned` machinery.

Out of scope

  • Removing `mBusWarned` from the class. Cost is 1 byte and keeping the field makes the conditional code symmetrical.
  • Gating `busKey = fl::string::from_literal(busName(mBus))` at line 401-403. `busKey` is still passed to `selectDriverForChannel` as a functional argument and can't be elided.

Related

🤖 Generated with Claude Code

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