Skip to content

Gate handleAllocateTxFailure's diagnostic-only locals + suggestion blocks in release #2956

Closed

Description

@zackees

Goal

Gate the diagnostic-only local-variable initializations + suggestion-block FL_WARN chains in `RmtMemoryManager::handleAllocateTxFailure` on `FASTLED_LOG_RUNTIME_ENABLED`. The FL_WARN bodies already collapse to `do {} while(0)` in release builds per Stage 1 (#2890), but the locals they feed (`total`, `allocated`, `reserved`, `available`) still get initialized — including a `getAvailableWords(true)` call.

Parent: #2886 — pattern consistency with #2918 / #2925 / #2929 / #2943 / #2950 / #2952.

Why this is a real win

`src/fl/channels/.../rmt_memory_manager.cpp.hpp:450-474`:

```cpp
// Fallback failed or not attempted - provide detailed diagnostic message
size_t total = mLedger.is_global_pool ? mLedger.total_words : mLedger.total_tx_words;
size_t allocated = mLedger.is_global_pool ? mLedger.allocated_words : mLedger.allocated_tx_words;
size_t reserved = mLedger.reserved_tx_words;
size_t available = getAvailableWords(true);

FL_WARN("RMT TX allocation failed for channel " << static_cast(channel_id));
FL_WARN(" Requested: " << words_needed << " words (...)");
FL_WARN(" Available: " << available << " words");
FL_WARN(" Memory breakdown: Total=" << total << ", Allocated=" << allocated
<< ", Reserved=" << reserved << " (external RMT usage)");

if (reserved > 0) {
FL_WARN(" Suggestion: " << reserved << " words reserved by external RMT usage ...");
FL_WARN(" Consider using DMA channels (use_dma=true) to bypass on-chip memory");
}
if (allocated > 0) {
FL_WARN(" Suggestion: " << allocated << " words already allocated to other channels");
FL_WARN(" Consider reducing LED count or using fewer channels");
}
if (mem_blocks > 2 && networkActive) {
FL_WARN(" Suggestion: Network mode uses 3× buffering ...");
FL_WARN(" Consider disabling network or using DMA channels");
}
```

In release builds: all FL_WARN bodies collapse, but `getAvailableWords(true)` still runs, the 3 `mLedger.*` reads still run, and the 3 conditional suggestion blocks still execute their (no-op) FL_WARN setup. Gating the whole block saves:

  • 1 `getAvailableWords(bool)` call
  • 3 `mLedger` field reads with ternary expressions
  • 3 conditional-branch tests (`if (reserved > 0)`, `if (allocated > 0)`, `if (mem_blocks > 2 && networkActive)`)
  • 9 empty FL_WARN body setups

`handleAllocateTxFailure` is the #16 symbol at 1,972 B in the audit. The body is mostly diagnostic-only; gating may cascade.

Deliverable

`src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp` — gate the diagnostic block

```cpp
// Fallback failed or not attempted - provide detailed diagnostic message
#if FASTLED_LOG_RUNTIME_ENABLED
size_t total = mLedger.is_global_pool ? mLedger.total_words : mLedger.total_tx_words;
size_t allocated = mLedger.is_global_pool ? mLedger.allocated_words : mLedger.allocated_tx_words;
size_t reserved = mLedger.reserved_tx_words;
size_t available = getAvailableWords(true);

FL_WARN("RMT TX allocation failed for channel " << static_cast<int>(channel_id));
FL_WARN("  Requested: " << words_needed << " words (" << mem_blocks << "× buffer"
        << (networkActive ? ", Network mode" : "") << ")");
FL_WARN("  Available: " << available << " words");
FL_WARN("  Memory breakdown: Total=" << total << ", Allocated=" << allocated
        << ", Reserved=" << reserved << " (external RMT usage)");

if (reserved > 0) {
    FL_WARN("  Suggestion: " << reserved << " words reserved by external RMT usage (e.g., USB CDC)");
    FL_WARN("              Consider using DMA channels (use_dma=true) to bypass on-chip memory");
}
if (allocated > 0) {
    FL_WARN("  Suggestion: " << allocated << " words already allocated to other channels");
    FL_WARN("              Consider reducing LED count or using fewer channels");
}
if (mem_blocks > 2 && networkActive) {
    FL_WARN("  Suggestion: Network mode uses 3× buffering (" << (mem_blocks * SOC_RMT_MEM_WORDS_PER_CHANNEL)
            << " words per channel)");
    FL_WARN("              Consider disabling network or using DMA channels");
}

#endif
```

The function's actual return value below the gated block (`return result<size_t, RmtMemoryError>::failure(...)`) is preserved unconditionally.

Behavior matrix

Build Outcome
Debug (`FASTLED_LOG_VERBOSITY=1`) Full diagnostic + suggestion block emitted
Release (`FASTLED_LOG_VERBOSITY=0`) Silent failure return; user accepted that constraint by disabling diagnostics

Acceptance

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

Expected savings

Projected ~50-300 B. `getAvailableWords` has 7 other callers, so cascade won't fire on it. The savings are from removing the local-variable initializations + the 3 conditional branch tests + the 9 empty FL_WARN setups. Realistic estimate: small but non-zero.

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