Skip to content

Cut ClocklessIdf5 bloat by gating cold-path emit helpers' sstream chains (~800 B) (#2886) #2917

Closed

Description

@zackees

Goal

Drop ~700-800 B from the ClocklessIdf5 transitive closure by gating the bodies of the FL_NO_INLINE cold-path emit helpers in the RMT5 driver on FASTLED_LOG_RUNTIME_ENABLED. In release builds (NDEBUG → FASTLED_LOG_VERBOSITY=0 per Stage 1), FL_WARN(...) is a no-op, but the fl::sstream construction + 15-20 operator<< chain side effects are still emitted because they happen BEFORE the FL_WARN expansion.

Parent: #2886 — fifth algorithmic-bloat reduction targeting symbols reachable from the ClocklessIdf5 static-init closure.

Why this is a real win

Two functions in src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp build elaborate diagnostic messages and then pass them to FL_WARN:

FL_NO_INLINE void emitRecoveryWarning(...) FL_NOEXCEPT {
    fl::sstream msg;                          // [1] constructed unconditionally
    msg << "\n=====...\n"                     // [2] 15 operator<< calls fire
        << "RMT ALLOCATION RECOVERY...\n"
        << "Expected: " << original_symbols << " ..."
        ... (15 multi-line literal + integer chain) ...
        << "=====";
    FL_WARN(msg.str());                       // [3] expands to no-op in release
}

In release builds:

  • FL_WARN(X) expands to do { if (false) { ... << X; } } while(0) — optimizer DCEs the inner block (msg.str() call elided).
  • BUT fl::sstream msg; at [1] is outside the if(false) block — it has visible side effects on msg's internal state, so the optimizer keeps the constructor + all 15 operator<< calls live in the function body.

The same pattern exists in emitAllocationFailureError (~418 B). Both functions live cold-side of FL_NO_INLINE, so the bytes are pinned in their own symbols. Together they contribute ~828 B to the binary even though they emit nothing at runtime in release builds.

Measured baseline (post-#2914 ELF, master @ 6bd4ebd9ec)

Symbol Size
fl::ChannelEngineRMTImpl::emitAllocationFailureError ($isra$0) 418 B
fl::ChannelEngineRMTImpl::emitRecoveryWarning ($isra$0) 410 B
fl::ChannelEngineRMTImpl::attemptAllocationRecovery (two copies) 187 + 128 = 315 B
Total in scope ~1,143 B

attemptAllocationRecovery contains the cold retry logic plus its own FL_LOG_RMT chains; only the FL_WARN/FL_LOG_RMT chains inside are gated, the retry-loop arithmetic stays.

Deliverable

Wrap each emit helper's body in #if FASTLED_LOG_RUNTIME_ENABLED. The function signature stays; the body becomes empty (parameters cast to (void)) when the gate is off.

FL_NO_INLINE void emitRecoveryWarning(
    size_t original_symbols, size_t reduced_symbols,
    size_t external_words) FL_NOEXCEPT {
#if FASTLED_LOG_RUNTIME_ENABLED
    fl::sstream msg;
    msg << "..." << original_symbols << " ..." << reduced_symbols << " ...";
    FL_WARN(msg.str());
#else
    (void)original_symbols;
    (void)reduced_symbols;
    (void)external_words;
#endif
}

Same pattern for emitAllocationFailureError (4 params). Same pattern for the FL_LOG_RMT and FL_WARN chains inside attemptAllocationRecovery (gate the body of each diagnostic block; keep the retry-loop arithmetic).

Also audit handleAllocateTxFailure in rmt_memory_manager.cpp.hpp:417-478 — already a FL_NO_INLINE cold helper, current size is only 63 B (Stage 1 already collapsed its FL_WARN chain). Verify and leave alone if confirmed clean.

Out of scope

  • Removing the FL_WARN calls from the source. They're useful in debug builds and should fire when FASTLED_LOG_VERBOSITY >= 1. The gate makes them release-build-free without losing debug-build diagnostics.
  • Auditing every FL_WARN call site in the RMT5 driver. The ones inline in processPendingChannels, createChannel, etc. are short enough that the sstream chain inlines into the hot function bodies where the optimizer can DCE them more aggressively. The targeted helpers are the FL_NO_INLINE cold-path ones where the bytes can't escape.

Acceptance

  1. emitRecoveryWarning, emitAllocationFailureError, and the FL_LOG_RMT chains inside attemptAllocationRecovery are gated on FASTLED_LOG_RUNTIME_ENABLED.
  2. bash lint --cpp passes.
  3. Behavior preserved in debug builds: FASTLED_LOG_VERBOSITY=1 (debug default) keeps the gate enabled — every diagnostic emits as before.
  4. Measured saving on release build: ~700-800 B drop in total_flash vs the current baseline (347,004 B). PR also lands the ratchet to the new measured number.

Expected savings

  • emitRecoveryWarning body: 410 B → ~10-20 B = −390 B
  • emitAllocationFailureError body: 418 B → ~10-20 B = −398 B
  • attemptAllocationRecovery diagnostic blocks: ~100-150 B
  • Net: ~700-900 B measured

The Stage 6 regression gate (tests/test_esp32s3_bloat_regression.py, baseline = 347004) validates the measurement on this PR's CI run. A follow-up commit lowers the baseline file in the same PR.

Related

🤖 Generated with Claude Code

Activity

  1. added 2 commits that reference this issue on Jun 7, 2026
    fcf51c5
    ded5eea
  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