Repository navigation
Description
Goal
Gate the diagnostic chain inside FASTLED_ASSERT(x, MSG) on FASTLED_LOG_RUNTIME_ENABLED. The condition check stays (assertion semantics preserved), but the fl::sstream() << "FASTLED ASSERT FAILED: " << MSG)).c_str() chain that fires on assertion FAILURE becomes a no-op in release builds where logging is already disabled.
Parent: #2886 — eighth algorithmic-bloat reduction. Mirrors the #2918 pattern: identify cold-path diagnostic chains the compiler can't DCE because their side-effects on a sstream are observable.
Why this is bloat
src/platforms/esp/esp_assert.h:13-18:
#define FASTLED_ASSERT(x, MSG) \
do { \
if (!(x)) { \
fl::println((fl::sstream() << "FASTLED ASSERT FAILED: " << MSG).c_str()); \
} \
} while (0)In release builds (NDEBUG → FASTLED_LOG_VERBOSITY=0 per Stage 1), this macro is not gated. The condition check + diagnostic block are emitted at every call site.
The optimizer leaves the fl::sstream() << ... << MSG chain inside the failure branch live because:
- The branch is conditional on a runtime value (
(x)), not a constant. - The sstream side effects are observable (heap allocation, sequential writes), so the optimizer can't DCE the chain even if it knows the branch is rarely taken.
There are 65 FASTLED_ASSERT call sites in src/ (per grep -c). Each adds ~30-50 B of unique diagnostic-chain code (the MSG literal + per-call-site operator<< instantiation). Cumulative bloat reachable in a Blink build: estimated ~1-2 KB.
Deliverable
src/platforms/esp/esp_assert.h — gate the diagnostic
#define FASTLED_ASSERT(x, MSG) \
do { \
if (!(x)) { \
+#if FASTLED_LOG_RUNTIME_ENABLED \
fl::println((fl::sstream() << "FASTLED ASSERT FAILED: " << MSG).c_str()); \
+#else \
+ (void)0; \
+#endif \
} \
} while (0)Same gating for src/platforms/assert_defs.h (the cross-platform fallback) and src/platforms/wasm/js_assert.h (the WASM emscripten variant).
The condition (x) is still evaluated for side effects — matching <cassert> semantics. The diagnostic message is suppressed in release.
Behavior matrix
| Build mode | Macro emits | Behavior on assertion failure |
|---|---|---|
Debug (FASTLED_LOG_VERBOSITY=1, no NDEBUG) |
full chain | prints "FASTLED ASSERT FAILED: " via fl::println |
Release (NDEBUG → FASTLED_LOG_VERBOSITY=0) |
condition check only | silent (matches C++ NDEBUG semantics for <cassert>) |
The C++ standard library precedent: <cassert>'s assert() macro is also NDEBUG-gated. FASTLED_ASSERT now follows the same convention.
Acceptance
src/platforms/esp/esp_assert.h— diagnostic gated onFASTLED_LOG_RUNTIME_ENABLED.src/platforms/assert_defs.h— same gate.src/platforms/wasm/js_assert.h— same gate.bash lint --cpppasses.- Measured against the post-perf(esp32): gate emit* cold helpers on FASTLED_LOG_RUNTIME_ENABLED (~800 B) #2918 ELF baseline (344,769 B), a release build should be ~1-2 KB lower. Baseline file ratchets in the same PR.
Expected savings
Conservative estimate: ~800 B - 2 KB measured on the ESP32-S3 NEOPIXEL Blink build. Variance reflects how many FASTLED_ASSERT call sites are reachable from the Blink transitive closure.
Out of scope
- Replacing FASTLED_ASSERT with C
assert()macros. Different API surface. - Adding a separate
FASTLED_DEBUG_ASSERTfor asserts that should be debug-only without the noise of full diagnostics. Future iteration. - Auditing every assert call site for correctness. They're correct; only the diagnostic chain is the bloat.
Related
- Meta: ESP32-S3 Blink bloat reduction (file:line concrete plan) — supersedes #2885 #2886 — parent meta + the audit cycle.
- perf(esp32): gate emit* cold helpers on FASTLED_LOG_RUNTIME_ENABLED (~800 B) #2918 — emit-helper gate (the immediate precedent — same pattern of identifying sstream-chain bloat that the macro can't DCE).
- perf(log): default FASTLED_LOG_VERBOSITY=0 in release builds (#2886 Stage 1) #2890 — Stage 1 (the
FASTLED_LOG_VERBOSITY=0default this gate piggybacks on).
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
perf(esp32): gate FASTLED_ASSERT diagnostic on FASTLED_LOG_RUNTIME_EN…
fix(esp32): correct FASTLED_ASSERT release no-op + ratchet baseline 3…