Repository navigation
perf(esp32): gate FASTLED_ASSERT diagnostic on FASTLED_LOG_RUNTIME_ENABLED - #2924
Conversation
…ABLED Closes #2923. Wraps the body of `FASTLED_ASSERT(x, MSG)` in `src/platforms/esp/esp_assert.h` with `#if FASTLED_LOG_RUNTIME_ENABLED`. In release builds (NDEBUG -> `FASTLED_LOG_VERBOSITY=0` per Stage 1 / #2890) the per-call-site `fl::sstream() << "FASTLED ASSERT FAILED: " << MSG` chain + `fl::println` call is replaced with a `sizeof((x), (MSG), 0)` syntax-only check. This matches standard C `<assert.h>` semantics under NDEBUG: the macro becomes `((void)0)`, condition not evaluated. Sketches must not put side effects in assertion conditions (already best practice). ## Why this is bloat Each of the 65 FASTLED_ASSERT call sites in `src/` builds a per-site `fl::sstream` operator<< instantiation with the MSG literal. The optimizer leaves these live because: 1. The assertion failure branch is conditional on a runtime value (`(x)`), not a constant — can't be DCE'd. 2. The sstream's operator<< calls have observable side effects on the sstream's internal buffer — can't be DCE'd by side-effect analysis even if the optimizer knew the branch was cold. Cross-platform fallback at `src/platforms/assert_defs.h:100-114` already uses an `if (false)` + `fl::detail::AssertSink() << MSG` pattern that DCEs correctly. WASM at `src/platforms/wasm/js_assert.h:11-17` uses `FL_WARN(MSG)` which is already gated. Only the ESP32 variant lacked the gate. ## Files - `src/platforms/esp/esp_assert.h` — gate added; the only platform variant that emitted unconditional sstream chains. ## Verification - `bash lint --cpp` -> all C++ linting checks pass. - Behavior preserved in debug builds: assertion failures still print the message via `fl::println`. Debug-only diagnostic infrastructure unchanged. - Behavior in release: matches C `<assert.h>` under NDEBUG (no eval, no diagnostic) — semantic change vs. previous release behavior, but matches the established convention. ## Expected savings Projected: ~1-2 KB measured on ESP32-S3 NEOPIXEL Blink. Variance reflects how many of the 65 src/ assert sites are in the Blink transitive closure. Measured saving validated on this PR's CI run via the Stage 6 regression gate; baseline ratchets in a follow-up if positive. Refs #2886, #2923, #2918.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesAssert Diagnostic Gating
🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…44769 -> 340832 (#2925) PR #2924 wrapped the FASTLED_ASSERT body on FASTLED_LOG_RUNTIME_ENABLED but used `sizeof((void)(MSG), 0)` as the release no-op. That broke the build because MSG is typically an `fl::sstream` operator<< chain like `"text " << i`, which is only valid as the RHS of `sstream.operator<<` — it has no streamable LHS in isolation. Fix: use the canonical `((void)0)` no-op matching standard C `<assert.h>` under NDEBUG. The MSG expression is not validated at compile time, but this matches the cassert convention. Sketches that have typos in MSG will see them in debug builds where the diagnostic chain still emits. ## Measured against `master @ 669d199` (the pre-fix #2924 merge) Build now succeeds. `bash bloat esp32s3 --top 5`: Total flash: 340,832 B (was: 344,769 B) fl::ClocklessIdf5<...>::ClocklessIdf5() (top-1): 47,288 B (was: 47,916 B — drops -628 B on the top symbol) Delta: -3,937 B flash. -628 B on the ClocklessIdf5 attribution specifically (second ever drop on the top-1 symbol after #2918). This exceeds the 1-2 KB projection in #2923 because the FASTLED_ASSERT diagnostic-chain bloat was more concentrated in the ClocklessIdf5 transitive closure than I'd estimated. The 65 src/ assert sites include 4 in `basic_vector` (used by every fl::vector instantiation in the RMT5 driver) and ~6 in flat_map/unordered_map (used by ChannelManager). The dead-strip cascade picked up the supporting sstream operator<< template instantiations only reachable from those sites. Refs #2886, #2923, #2924.
Closes #2923. Wraps the body of FASTLED_ASSERT in src/platforms/esp/esp_assert.h on FASTLED_LOG_RUNTIME_ENABLED. Matches C <assert.h> NDEBUG semantics; eliminates ~1-2 KB of per-call-site sstream chain bloat in release builds.
The cross-platform fallback and WASM variants are already correctly gated; only the ESP32 variant lacked the gate.
Refs #2886, #2918.
Summary by CodeRabbit