Skip to content

perf(esp32): gate FASTLED_ASSERT diagnostic on FASTLED_LOG_RUNTIME_ENABLED - #2924

Merged
zackees merged 1 commit into
masterfrom
feat/2923-gate-assert-diagnostic
Jun 7, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2923-gate-assert-diagnostic

Conversation

@zackees

@zackees zackees commented Jun 7, 2026 •

Copy link
Copy Markdown
Member

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

  • Improvements
    • Enhanced assertion handling for ESP platform with configurable runtime behavior. When enabled, assertions now display detailed failure messages; when disabled, they optimize for production by validating code syntax at compile-time without runtime overhead.

…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.
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 7, 2026
@zackees
zackees merged commit 669d199 into master Jun 7, 2026
5 of 7 checks passed
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f524c191-c097-4c01-aa64-02917aa32b06

📥 Commits

Reviewing files that changed from the base of the PR and between 9f9abd9 and 4eb3872.

📒 Files selected for processing (1)
  • src/platforms/esp/esp_assert.h

📝 Walkthrough

Walkthrough

src/platforms/esp/esp_assert.h now includes the logging header and gates the FASTLED_ASSERT macro diagnostic on FASTLED_LOG_RUNTIME_ENABLED. When logging is enabled, the macro prints assertion failures; when disabled, it reduces to a compile-time-only expression-validation no-op.

Changes

Assert Diagnostic Gating

Layer / File(s) Summary
Assert diagnostic gating on logging runtime state
src/platforms/esp/esp_assert.h
FASTLED_ASSERT(x, MSG) now depends on fl/log/log.h to gate its runtime diagnostic chain. When FASTLED_LOG_RUNTIME_ENABLED is true, the macro prints "FASTLED ASSERT FAILED: " plus MSG via fl::println(fl::sstream() << ...) on assertion failure. When disabled, the macro becomes a no-op that still validates the syntax of both x and MSG at compile time via sizeof(...) without evaluating them.

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

  • #2917: Both changes gate diagnostic and warning emission on the same compile-time flag FASTLED_LOG_RUNTIME_ENABLED, applying the same pattern of suppressing cold-path sstream chains in release builds.

Possibly related PRs

  • FastLED/FastLED#2791: Introduces the logging gate infrastructure in fl/log/log.h that this PR depends on to conditionally enable/disable the assertion diagnostic output.
  • FastLED/FastLED#2863: Adds new logging macro variants (FL_WARN_LIT, FL_LOG_LIT) gated by the same FASTLED_LOG_RUNTIME_ENABLED flag, sharing the same pattern of compile-time diagnostic suppression.

Poem

🐰 A hop and a gate, so neat and so fine,
When logs are disabled, assertions align!
No diagnostic chains in the cold-path code,
Just syntax checks keeping the compile path stowed! 🌿

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2923-gate-assert-diagnostic

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 7, 2026
zackees added a commit that referenced this pull request Jun 7, 2026
…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.
@zackees
zackees deleted the feat/2923-gate-assert-diagnostic branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Gate FASTLED_ASSERT diagnostic on FASTLED_LOG_RUNTIME_ENABLED (~1-2 KB) (#2886)

1 participant