Repository navigation
Description
Tracked in #2974 (sub-issue G).
Symbol
fl::RmtMemoryManager::handleAllocateTxFailure(unsigned char, unsigned int, unsigned int, bool) — 1,710 B on ESP32-S3 fbuild post-#2968.
Defined in src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp (lines 417-484), declared in src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.h (line 465). Already marked FL_NO_INLINE and extracted from allocateTx for #2773 item 2.5 — but the function body itself is still pure error-reporting bloat.
Top callees (per-symbol bloat report)
| Callee | Bytes |
|---|---|
fl::vector_basic::push_back_move_impl(void*) |
234 |
fl::detail::log_emit(...) |
222 |
fl::expected<unsigned int, fl::RmtMemoryError>::failure(RmtMemoryError, char...) |
168 |
_Unwind_Resume |
156 |
fl::RmtMemoryManager::getAvailableWords(bool) const |
114 |
fl::fastled_file_offset |
113 |
fl::sstream::appendFormatted(long) |
83 |
fl::sstream::appendFormatted(unsigned long) |
83 |
fl::RmtMemoryManager::tryAllocateWords(unsigned int, bool) |
65 |
So the bulk of the 1,710 B is per-call-site sstream ctor + operator<< chain + log_emit + landing-pad metadata, repeated across 11 log sites:
- 4 ×
FL_LOG_RMT(fallback retry path, lines 436-447) - 7 ×
FL_WARN(diagnostic block, lines 461-480)
Pattern
The diagnostic block is repetitive. Each FL_WARN formats a handful of size_t values into a fixed template, e.g.:
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)\");
// ... 5 more FL_WARN sites with conditional suggestionsEach site instantiates an fl::sstream, runs the << chain (each integer pulls in appendFormatted(unsigned long) glue), calls log_emit(LOG_WARN, __FILE__, __LINE__, ss), and emits a landing pad because ~sstream/~basic_string can throw. Per-site cost: ~200-300 B inline + ~100-200 B unwind metadata. Repeated 7-11× → most of the symbol.
The FL_LOG_RMT/FL_WARN formatting is not unique per site in any meaningful way — it's the same template (a fixed prefix string + 1-3 integer interpolations) with different values. This is the textbook case for moving the format machinery out-of-line.
Proposed fix
Extract a single FL_NO_INLINE cold helper in the .cpp.hpp (file-local / anonymous namespace), e.g.:
// Anonymous namespace, file-local.
FL_NO_INLINE static void emitAllocTxFailureDiagnostic(
u8 channel_id, size_t words_needed, size_t mem_blocks, bool networkActive,
size_t total, size_t allocated, size_t reserved, size_t available) FL_NOEXCEPT {
#if FASTLED_LOG_RUNTIME_ENABLED
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\");
}
#else
(void)channel_id; (void)words_needed; (void)mem_blocks; (void)networkActive;
(void)total; (void)allocated; (void)reserved; (void)available;
#endif
}
FL_NO_INLINE static void emitAllocTxFallbackLog(
size_t mem_blocks, size_t words_needed, size_t fallback_words,
u8 channel_id, bool success) FL_NOEXCEPT { /* the 4 FL_LOG_RMT sites */ }Then handleAllocateTxFailure becomes a thin orchestrator that:
- Calls
tryAllocateWords(single-buffer retry) - On success: pushes the ledger entry, logs via
emitAllocTxFallbackLog, returnssuccess(fallback_words) - On failure: gathers
total/allocated/reserved/availablevia existing accessors, callsemitAllocTxFailureDiagnostic(...), returnsexpected::failure(RmtMemoryError::INSUFFICIENT_TX_MEMORY)
The helpers are file-local so the linker drops them entirely in builds that don't reference handleAllocateTxFailure (none today, but defensive).
Estimated savings
- All 11 sstream construct +
<<chain +log_emitcall expansions move into the helper bodies (which exist exactly once instead of being inlined into the 1,710 B caller). - Landing-pad metadata (~100-200 B × 7-11 sites) consolidates into the helper's single landing pad.
- The helper itself costs ~400-600 B (shipped once).
- Net savings on
handleAllocateTxFailure: ~800-1200 B (the symbol should shrink to ~500-900 B, mostly theexpected::failureglue + thetryAllocateWords/push_backcalls + parameter marshalling).
Logging preservation
Logging output is identical — same FL_WARN/FL_LOG_RMT macros, same message templates, same severity, same __FILE__/__LINE__ (the file/line will now point at the helper, which is fine — these are diagnostic warnings, not stack traces). The helpers respect FASTLED_LOG_RUNTIME_ENABLED, matching today's gating on the diagnostic block.
Refs
- Reduce per-symbol bloat in the FastLED 1-4KB function band on ESP32-S3 (logging must stay enabled) #2974 (meta — sub-issue G)
- Meta: ESP32-S3 binary-size reduction — Batch 1 (~26 KB) + Batch 2 (~26–50 KB) (supersedes #2771) #2773 item 2.5 (original extraction of
handleAllocateTxFailurefromallocateTx) - Gate handleAllocateTxFailure's diagnostic-only locals + suggestion blocks in release #2956 (FASTLED_LOG_RUNTIME_ENABLED gating around the diagnostic block — already in place)
- Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886 / perf(log): default FASTLED_LOG_VERBOSITY=0 in release builds (#2886 Stage 1) #2890 (release-mode log verbosity gating)
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity