Repository navigation
feat(log): FASTLED_LOG_VERBOSITY release knob — opt-in −43 KB on ESP32-S3 (#2773 item 2.3) - #2791
Conversation
…2-S3 (#2773 item 2.3) Adds a release-mode verbosity knob that lets users no-op all of FL_WARN / FL_INFO / FL_ERROR / FL_PRINT / FL_DBG with a single `#define FASTLED_LOG_VERBOSITY=0`, freeing the ~46 KB of `.flash.rodata` string-pool bloat that those macros bake into `main.cpp.o` via `__FILE__:__LINE__:msg` literals at every call site. ## Why Per the #2473 audit (#2473 (comment)), the single biggest `.flash.rodata` contributor on the ESP32-S3 NEOPIXEL Blink build is the merged `.str1.1` string pool in `main.cpp.o` (~57 KB) — the union of every FL_WARN/FL_LOG format string inlined into the sketch TU from FastLED headers. These strings are live whenever their call sites are live, and the call sites are live in any build where `SKETCH_HAS_LARGE_MEMORY` is set (true on ESP32-S3, Teensy 4, etc.). The audit's item 2.3 calls this out as the highest-value remaining size-reduction lever in the meta-issue. This PR ships the knob. ## What Three levels, mirroring standard log-verbosity conventions (higher = more output): * `FASTLED_LOG_VERBOSITY == 0` → ALL of FL_WARN / FL_INFO / FL_ERROR / FL_PRINT / FL_DBG expand to `do {} while(0)`. Strings disappear, `fl::sstream` uses vanish, and any transitive `fl::println` references die. * `FASTLED_LOG_VERBOSITY == 1` (default) → current behavior; FL_WARN / FL_INFO / FL_ERROR / FL_PRINT fire on platforms where `SKETCH_HAS_LARGE_MEMORY` is set. FL_DBG follows its existing `FASTLED_HAS_DBG` gate. * `FASTLED_LOG_VERBOSITY >= 2` → reserved for future "even noisier than debug" output; currently equivalent to 1. Host unit tests (`FASTLED_TESTING` defined) pin verbosity to 1 unconditionally so assertion and warning diagnostics keep firing in CI. ## Measured (ESP32-S3, examples/Blink/Blink.ino, PIO + IDF 5.4) | Build | firmware.bin | Δ vs master | |---|---:|---:| | master (`8c87cbfddb`, no knob) | 657,392 B | — | | this PR, default (`FASTLED_LOG_VERBOSITY=1`)| 657,392 B | **±0 B (no behavior change)** | | this PR, `-DFASTLED_LOG_VERBOSITY=0` | **613,792 B**| **−43,600 B (~6.6%)** | ## Migration **None for the default.** The default value is 1, which preserves current behavior byte-for-byte. The ~43 KB savings are opt-in via the `FASTLED_LOG_VERBOSITY=0` build flag. Embedded users who want the savings add one line to their `platformio.ini`: ```ini build_flags = -DFASTLED_LOG_VERBOSITY=0 ``` Host CI keeps the diagnostics regardless of any explicit setting — `FASTLED_TESTING` overrides any `FASTLED_LOG_VERBOSITY < 1` upward to 1. ## Implementation A new resolved compile-time gate, `FASTLED_LOG_RUNTIME_ENABLED`, combines the existing `SKETCH_HAS_LARGE_MEMORY` platform gate with the new `FASTLED_LOG_VERBOSITY >= 1` user gate. Every `#if SKETCH_HAS_LARGE_MEMORY` in `fl/log/log.h` flips to `#if FASTLED_LOG_RUNTIME_ENABLED`. FL_DBG's priority chain gains one extra clause (FASTLED_LOG_VERBOSITY=0 forces FL_DBG to no-op above the existing FASTLED_FORCE_DBG / SKETCH_HAS_LARGE_MEMORY heuristics). ## Verification - [x] `bash lint --cpp` — clean. - [x] `bash compile esp32s3 --examples Blink --platformio` (default `FASTLED_LOG_VERBOSITY=1`) → 657,392 B (byte-identical to pre-PR master baseline). - [x] `bash compile esp32s3 --examples Blink --platformio --defines FASTLED_LOG_VERBOSITY=0` → **613,792 B (−43,600 B)**. - [x] `bash test --cpp` — 309/309 pass (host tests pin VERBOSITY=1). Issue: #2773 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR introduces a compile-time ChangesLogging Verbosity Control
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/fl/log/log.h (1)
138-138: ⚡ Quick winReplace Unicode em dash with ASCII equivalent.
Line 138 uses "—" (em dash, Unicode U+2014). Per coding guidelines, C++ source files should be ASCII-only.
The same applies to lines 189, 229.
Proposed fix
-// No-op macros — either memory-constrained platform or FASTLED_LOG_VERBOSITY=0. +// No-op macros -- either memory-constrained platform or FASTLED_LOG_VERBOSITY=0.Apply similar fix at lines 189, 229.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/fl/log/log.h` at line 138, Replace the Unicode em dash characters in the comment blocks of src/fl/log/log.h with an ASCII hyphen-minus: find the comment "No-op macros — either memory-constrained platform or FASTLED_LOG_VERBOSITY=0." and the similar comment occurrences later in the same header (two other comment lines using an em dash) and change "—" to "-" so the file remains ASCII-only; ensure identical replacements are applied to all three occurrences.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/fl/log/log.h`:
- Line 138: Replace the Unicode em dash characters in the comment blocks of
src/fl/log/log.h with an ASCII hyphen-minus: find the comment "No-op macros —
either memory-constrained platform or FASTLED_LOG_VERBOSITY=0." and the similar
comment occurrences later in the same header (two other comment lines using an
em dash) and change "—" to "-" so the file remains ASCII-only; ensure identical
replacements are applied to all three occurrences.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7ac85ae1-5388-4651-8d97-3c19f0b253e9
📒 Files selected for processing (1)
src/fl/log/log.h
…5 Level A)
When users opt in via:
#define FASTLED_RMT_STATIC_ALLOCATION 1
#include <FastLED.h>
calculateMemoryBlocks() collapses to a single `return FASTLED_RMT_MEM_BLOCKS`
unconditional constant — no memory-pressure detection, no network-aware
buffering, no single-buffer fallback retry, no diagnostic FL_LOG_RMT chains.
The runtime allocateTx path that depends on this then trivially constant-
folds through the linker.
The opt-in asserts at compile time that the sketch has:
- Exactly one addLeds<>() call, made before setup() returns
- No removeLeds() / late addLeds()
- No WiFi/Ethernet/Bluetooth during LED transmission
Default behavior (FASTLED_RMT_STATIC_ALLOCATION=0) is unchanged — the
adaptive planner stays live for all sketches that didn't opt in.
This is "Level A" of the design RFC posted on #2773. Level B (full
template-trait refactor with linker-driven specialization selection) is
deferred; Level A captures ~70% of item 2.5's headroom at minimal risk.
Estimated savings under FASTLED_RMT_STATIC_ALLOCATION=1:
~2-3 KB code on top of FASTLED_LOG_VERBOSITY=0 (#2791).
FastLED#2856 item 3.6) Under FASTLED_RMT_STATIC_ALLOCATION=1 (FastLED#2846) the user has asserted no removeLeds() / late addLeds(). The destructor of ChannelEngineRMTImpl still calls memMgr.free() / memMgr.freeDMA() on every channel at process end, but the ledger isn't meaningfully tracked under static mode so the work is dead — yet it still pulls fl::vector_inlined::erase, the begin/end iterator chain, and the multi-line FL_LOG_RMT / FL_WARN operator<< instantiations into the binary. Skip both bodies under the macro. Default behavior (FASTLED_RMT_STATIC_ALLOCATION=0) is unchanged. Refs FastLED#2856 item 3.6. Stacks on FastLED#2846 (FASTLED_RMT_STATIC_ALLOCATION opt-in macro). Estimated savings: ~few hundred bytes additional when both FastLED#2791 (FASTLED_LOG_VERBOSITY=0) and FastLED#2846 are also opted in.
…#2856 item 3.5) The existing allocateTx / allocateRx return result<size_t, RmtMemoryError> — a sum type with discriminator + payload. At the 4 internal callers inside the RMT5 driver chain (ChannelEngineRMT::createChannel × 2, RmtRxChannelImpl::ctor + begin) the specific error code is never read; callers just log + return false on any failure. Add tryAllocateTx / tryAllocateRx wrappers returning bool + size_t out parameter. The result<>-bearing API is retained for callers that need error fidelity (tests, future callers, the public surface). Migrate the 4 internal sites to the new API. Mock RmtMemoryManager (rmt5_support_stubs.h) gets matching always-succeeds stubs so the host test build still links. Refs FastLED#2856 item 3.5. Estimated savings: small (call-site result<> constructor + .ok() + .value() decoded into bool check + out param read). Real win compounds with FastLED#2791 (FASTLED_LOG_VERBOSITY=0) and FastLED#2846 (FASTLED_RMT_STATIC_ALLOCATION=1) where the FL_WARN diagnostic chains already disappear.
…tage 1) (#2890) * perf(log): default FASTLED_LOG_VERBOSITY=0 in release builds (#2886 Stage 1) Flips the unset default of `FASTLED_LOG_VERBOSITY` from `1` to `0` when `NDEBUG` is defined (i.e. release builds). Test builds (`FASTLED_TESTING`) and debug builds (no `NDEBUG`) still default to `1`, so `FL_WARN` and `FL_ERROR` stay live by default whenever you are not on a release build — which is what the user-facing experience demands. Resolution order: - FASTLED_TESTING is set → 1 (host unit tests need full diagnostics) - NDEBUG is set (release) → 0 (drops ~55 KB of FL_WARN/FL_LOG strings on ESP32-S3 NEOPIXEL Blink; see #2886 "Stage 1" projection) - otherwise (debug builds) → 1 (preserves current behavior) Users on release builds who explicitly want FL_WARN/FL_LOG back set `-DFASTLED_LOG_VERBOSITY=1` in their build flags, or `#define FASTLED_LOG_VERBOSITY 1` before `#include <FastLED.h>`. The per-channel logging defines (`FASTLED_LOG_RMT_ENABLED`, `FASTLED_LOG_SPI_ENABLED`, etc.) keep their existing gates — only the verbosity floor changes here. This is Stage 1 of the multi-stage ESP32-S3 bloat-reduction plan tracked in #2886. The projected savings of ~55 KB collapse the per-call-site rodata pools attributed to the 75 FL_WARN/FL_LOG sites in `channel_driver_rmt.cpp.hpp`, the 59 sites in `rmt_memory_manager.cpp.hpp`, the 6 sites in `manager.cpp.hpp`, and the 5 sites in `channel.cpp.hpp` — all reachable from the ClocklessIdf5 ctor transitive closure that currently anchors 58,770 B of the 388,380 B Blink binary. No public API changes. The `FASTLED_LOG_VERBOSITY` macro and its three levels remain stable (introduced in #2791); only the unset default flips. Refs #2886, #2791, #2773. * docs(review): encode FL_WARN/FL_ERROR default-visibility invariant Add the invariant "FL_WARN and FL_ERROR remain active by default on NON-release builds" to two review surfaces so the rule is enforced on every future PR: 1. `.claude/skills/code-review/review-rules.md` — local code-review agent (run via `/code-review`) gets a new "FL_WARN/FL_ERROR default-visibility invariant" section. Reviews flag any change that adds an outer guard requiring opt-in on debug builds, lowers the non-release default of `FASTLED_LOG_VERBOSITY` below 1, or introduces a new logging knob that suppresses warnings/errors by default on non-release builds. 2. `.coderabbit.yaml` — two `path_instructions` entries: - `src/fl/log/**` — the verbosity-default contract is stated with the resolution order from log.h (FASTLED_TESTING → 1, NDEBUG → 0, otherwise → 1) and the rationale (developers depend on warnings firing during development). - `src/**/*.{h,hpp,cpp,cpp.hpp,impl.hpp}` — broader call-site rule: PRs are flagged only when they wrap existing or new FL_WARN / FL_ERROR sites in additional `#if !defined(...)` blocks that would suppress them on non-release builds by default. New FL_WARN/FL_ERROR call sites are fine because they inherit the correct default from the verbosity gate already. Release builds (NDEBUG defined) intentionally default to 0; that is the savings the bloat-reduction work in #2886 Stage 1 delivers. Refs #2886, #2890.
…2886 Stage 2) (#2894) Closes #2893. Adds a build-flag-gated strong override of the Arduino-ESP32 core's `shouldPrintChipDebugReport()` weak symbol. Setting build_flags = -DFASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT=1 in `platformio.ini` (or the equivalent in Arduino IDE `compiler.cpp.extra_flags`) makes the optimizer fold both `if (shouldPrintChipDebugReport())` branches at vendor `main.cpp:55` and `main.cpp:63` to dead code. `--gc-sections` then drops `printBeforeSetupInfo()` (~1,464 B at top-25 row #21 of #2886) plus its ~1-2 KB of formatted-stream rodata carrier strings — projected ~3 KB of flash savings on the ESP32-S3 NEOPIXEL Blink baseline. ## Why a build flag, not an include? The earlier design (an opt-in include `#include <extras/suppress_arduino_chip_debug_report.cpp.hpp>` in the user sketch) collided with the unity-build linter: every `.cpp.hpp` under `src/` is required to participate in a `_build.cpp.hpp` aggregator, which in turn is compiled by a `+.cpp` wrapper in `src/fl/build/`. The shim file is therefore unavoidably part of the library compilation unit. Gating the body on `FASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT` and `FL_IS_ESP32` keeps the default behavior unchanged for every user who doesn't explicitly opt in. Opt-in via build flag is the same ergonomic shape as `FASTLED_RMT_STATIC_ALLOCATION` (#2846) and `FASTLED_LOG_VERBOSITY` (#2791) — recognizable to existing users following the bloat-reduction docs. ## Files - `src/extras/suppress_arduino_chip_debug_report.cpp.hpp` — the shim. Empty body unless `FL_IS_ESP32 && FASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT`. - `src/extras/_build.cpp.hpp` — unity-build aggregator for `extras/`, documented as the home for build-flag-gated shims. - `src/fl/build/extras+.cpp` — independently-compiled wrapper TU that pulls `extras/_build.cpp.hpp` into the library build (matches the existing `platforms+.cpp` / `third_party+.cpp` pattern). - `ci/lint_cpp/test_unity_build.py` — register `fl/build/extras+.cpp` in `EXPECTED_BUILD_FILES` so the unity-build linter accepts the new wrapper. ## Verification - `bash lint --cpp` → all C++ linting checks pass; the pre-existing PlatformIO-internal-usage warnings (issue #2701) are warn-only and unchanged by this PR. - Flash savings (`bash bloat esp32s3 --build` with `-DFASTLED_SUPPRESS_ARDUINO_CHIP_DEBUG_REPORT=1`) measured by the Stage 6 verification gate; this PR only ships the mechanism. ## User-facing behavior | Build flag | ESP32 target | Effect | |---|---|---| | unset / `=0` | yes | no change (vendor weak default fires) | | `=1` | yes | strong override → `printBeforeSetupInfo()` dead-stripped | | any | no | shim expands to nothing | Refs #2886, #2893.
Summary
Adds a release-mode verbosity knob that lets users no-op all of
FL_WARN / FL_INFO / FL_ERROR / FL_PRINT / FL_DBG with a single build
flag, freeing ~43 KB on ESP32-S3 NEOPIXEL Blink.
Implements item 2.3 of #2773 — the biggest single-line size win on
the punch list.
Mechanism
Per the #2473 audit, the single biggest
.flash.rodatacontributor onthe ESP32-S3 Blink build is the merged
.str1.1string pool inmain.cpp.o(~57 KB) — the union of everyFL_WARN/FL_LOGformatstring inlined into the sketch TU from FastLED headers. These strings
are live whenever their call sites are live, and the call sites are
live in any build where
SKETCH_HAS_LARGE_MEMORYis set (true onESP32-S3, Teensy 4, etc.).
This PR adds a
FASTLED_LOG_VERBOSITYgate AND combines it with theexisting
SKETCH_HAS_LARGE_MEMORYplatform gate via a new resolvedFASTLED_LOG_RUNTIME_ENABLEDmacro. When verbosity is 0, every macroexpands to
do {} while(0), the strings die, thefl::sstreamusesvanish, and any transitive
fl::printlnreferences can be dropped by--gc-sections.Verbosity levels
FASTLED_LOG_VERBOSITY == 0do {} while(0). Strings, sstream, println references all GC'd.FASTLED_LOG_VERBOSITY == 1(default)SKETCH_HAS_LARGE_MEMORYis set. FL_DBG follows its existingFASTLED_HAS_DBGgate.FASTLED_LOG_VERBOSITY >= 2Host unit tests (
FASTLED_TESTINGdefined) pin verbosity to 1unconditionally so assertion and warning diagnostics keep firing in CI.
Measured (ESP32-S3, examples/Blink/Blink.ino, PIO + IDF 5.4)
firmware.bin8c87cbfddb, no knob)FASTLED_LOG_VERBOSITY=1)-DFASTLED_LOG_VERBOSITY=0Migration
None for the default. Existing sketches see byte-identical
behavior — the default value 1 preserves the current behavior. The
~43 KB savings are opt-in via:
Or in Arduino, define before
#include <FastLED.h>:Host CI keeps the diagnostics regardless of any explicit setting —
FASTLED_TESTINGoverrides anyFASTLED_LOG_VERBOSITY < 1upward to 1.Implementation
Introduces
FASTLED_LOG_RUNTIME_ENABLED = (SKETCH_HAS_LARGE_MEMORY && FASTLED_LOG_VERBOSITY >= 1)and flips every#if SKETCH_HAS_LARGE_MEMORYin
fl/log/log.hto use it. FL_DBG's priority chain gains one extraclause (
FASTLED_LOG_VERBOSITY=0forces FL_DBG to no-op above theexisting
FASTLED_FORCE_DBG/SKETCH_HAS_LARGE_MEMORYheuristics).The two gates remain logically independent — embedded targets without
SKETCH_HAS_LARGE_MEMORYare no-op regardless of the verbosity knob(matching the pre-PR behavior on AVR/ATtiny).
Test plan
bash lint --cpp— clean.FASTLED_LOG_VERBOSITY=1) → 657,392 B, identicalto pre-PR master baseline.
-DFASTLED_LOG_VERBOSITY=0) → 613,792 B(−43,600 B).
bash test --cpp— 309/309 pass (host tests pin VERBOSITY=1).Issue: #2773
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Improvements