Repository navigation
Description
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 todo { 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 onmsg'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
emitRecoveryWarning,emitAllocationFailureError, and the FL_LOG_RMT chains insideattemptAllocationRecoveryare gated onFASTLED_LOG_RUNTIME_ENABLED.bash lint --cpppasses.- Behavior preserved in debug builds:
FASTLED_LOG_VERBOSITY=1(debug default) keeps the gate enabled — every diagnostic emits as before. - Measured saving on release build: ~700-800 B drop in
total_flashvs the current baseline (347,004 B). PR also lands the ratchet to the new measured number.
Expected savings
emitRecoveryWarningbody: 410 B → ~10-20 B = −390 BemitAllocationFailureErrorbody: 418 B → ~10-20 B = −398 BattemptAllocationRecoverydiagnostic 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
- Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886 — parent meta + audit comments.
- perf(esp32): add fl::sort_small for bounded containers; cut ClocklessIdf5 bloat #2908 / perf(gamma): use fl::s16x16::pow for Gamma8 LUT + applyGamma_video; drop __ieee754_pow #2911 / perf(esp32): gate SPI dispatch in Channel::showPixels behind FASTLED_DISABLE_SPI_CHIPSETS #2914 — prior algorithmic-bloat PRs.
- docs(esp32): add CONFIG_NEWLIB_NANO_FORMAT=y to Stage 3 sdkconfig overlay (~20-30 KB) #2916 — most recent overlay extension (nano-newlib).
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
perf(esp32): gate emitRecoveryWarning + emitAllocationFailureError bo…
chore(bloat): ratchet baseline 347004 -> 344769 (post-#2918 emit-gate) (
perf(rmt5): gate handleAllocateTxFailure diagnostic block (#2956) (#2957