Skip to content

Skip Channel auto-naming in release builds (~100-300 B) (#2886) #2942

Closed

Description

@zackees

Goal

Skip the "Channel_<id>" auto-naming work in release builds where the resulting name is only consumed by no-op'd FL_WARN/FL_ERROR diagnostics. Drops fl::to_string instantiation + string concatenation from fl::Channel::Channel(...) and fl::Channel::create(...).

Parent: #2886 — small tactical win on top of the cumulative session work.

Why this is a real win

fl::Channel::Channel(...) at src/fl/channels/channel.cpp.hpp:195 initializes mName(makeName(mId)) in its member initializer list. makeName at src/fl/channels/channel.cpp.hpp:156-161:

fl::string Channel::makeName(i32 id, const fl::optional<fl::string>& configName) {
    if (configName.has_value()) {
        return configName.value();
    }
    return "Channel_" + fl::to_string(static_cast<i64>(id));
}

The "Channel_" + fl::to_string(static_cast<i64>(id)) path runs for every channel constructed without an explicit name (which is every legacy addLeds<> flow). It pulls in:

  • fl::to_string(i64) — typically a switch + per-digit conversion
  • fl::string::operator+(const char*, fl::string) — heap allocation + concatenation
  • The fl::string move-out from makeName's return

For release builds (NDEBUG → FASTLED_LOG_VERBOSITY=0), mName is consumed only by FL_WARN / FL_ERROR sites that all expand to do { } while(0) per #2890. The name never reaches println/sstream — every read site dead-strips.

The remaining mName reads — passed to ReorderingPixelIteratorAny iterator(pixels, mScreenMap.getXYMap(), mRgbOrder, mSettings.rgbw(), mSettings.rgbww(), mName) at src/fl/channels/channel.cpp.hpp:499 — also feed into the iterator's own FL_WARN sites. Same logic applies: empty mName is fine in release.

Deliverable

src/fl/channels/channel.cpp.hpp — gate the auto-naming

fl::string Channel::makeName(i32 id, const fl::optional<fl::string>& configName) {
    if (configName.has_value()) {
        return configName.value();
    }
#if FASTLED_LOG_RUNTIME_ENABLED
    return "Channel_" + fl::to_string(static_cast<i64>(id));
#else
    (void)id;
    return {};
#endif
}

User-provided names (via Channel::create(cfg) with cfg.mName.has_value()) are unaffected — they keep their explicit value in both debug and release builds.

Behavior matrix

Build configName set? mName value
Debug (FASTLED_LOG_VERBOSITY=1) yes configName.value()
Debug no "Channel_<id>"
Release (FASTLED_LOG_VERBOSITY=0) yes configName.value()
Release no "" (empty)

The release-build "Channel ''" rendering doesn't appear anywhere because the FL_WARN/FL_ERROR sites that would emit it are all collapsed to no-ops per Stage 1.

Acceptance

  1. Channel::makeName gated on FASTLED_LOG_RUNTIME_ENABLED.
  2. bash lint --cpp passes.
  3. Behavior preserved in debug builds.
  4. Measured saving validated on post-merge build; baseline ratchets if positive.

Expected savings

Projected ~100-300 B. The fl::to_string + string concat + heap allocation path is non-trivial but small. The dead-strip cascade pattern from #2918 / #2925 / #2929 may push this higher if fl::to_string<i64> was reachable only from this site.

Out of scope

  • Removing mName as a field. Public API (Channel::getName()).
  • Gating the FL_WARN/FL_ERROR sites that read mName. Already collapsed by Stage 1.

Related

🤖 Generated with Claude Code

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