Skip to content

feat(log): FASTLED_LOG_VERBOSITY release knob — 33 KB Blink savings (#2773 item 2.3) - #2789

Closed
zackees wants to merge 1 commit into
masterfrom
feat/2773-log-verbosity-knob
Closed

zackees wants to merge 1 commit into
masterfrom
feat/2773-log-verbosity-knob

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Implements item 2.3 from the ESP32-S3 binary-size meta tracker (#2773) — the projected single biggest remaining lever, validated on stock Blink at the projected savings range.

What this adds

A three-level FASTLED_LOG_VERBOSITY knob gating FL_WARN / FL_INFO / FL_ERROR / FL_PRINT (and their _IF/_ONCE/_EVERY/_FMT siblings):

#ifndef FASTLED_LOG_VERBOSITY
#if defined(FASTLED_NO_LOG) && FASTLED_NO_LOG
#define FASTLED_LOG_VERBOSITY 0
#else
#define FASTLED_LOG_VERBOSITY 1
#endif
#endif
  • =1 (default, no change vs master) — full stream formatting on platforms where SKETCH_HAS_LARGE_MEMORY allows it
  • =0 — each macro expands to do { if (false) { (void)(fl::sstream_noop() << X); } } while (0). User stream expressions stay type-checked but the format strings dead-strip
  • =2 — reserved for future use; currently behaves like =1

FASTLED_NO_LOG=1 is honored: it forces level 0 so existing opt-out scripts keep working with the new gate.

Why this works

#2773's analysis pinpointed .str1.1 (the merged rodata pool of every FL_WARN/FL_LOG format string baked into the sketch translation unit) as ~58 KB — by far the single biggest rodata contributor on stock Blink. With if (false) guarding the sstream chain, the optimizer drops the whole branch before --gc-sections ever sees the literal references — including the __FILE__ + __LINE__ + WARN: + user-message tokens at every call site.

Empirical savings (ESP32-S3 Blink, PlatformIO + IDF 5.4)

Build firmware.bin
master baseline (verbosity defaults to 1) 654,192 B
-DFASTLED_LOG_VERBOSITY=0 620,384 B

Net: –33,808 B (–33 KB, –5.2 %). Right in the meta tracker's 20–40 KB projection range.

What does NOT change

  • Default behavior — FASTLED_LOG_VERBOSITY unset → level 1 → byte-for-byte identical to current master. Users who haven't opted in see no change in either behavior or binary size.
  • Side-effect semantics in log calls — FL_WARN("…" << ++counter) is not preserved at level 0, consistent with the documented contract of logging macros across the Arduino ecosystem (logging shouldn't have side effects). At level 1 the existing behavior is unchanged.
  • Other log macros — FL_DBG, the FASTLED_LOG_*_ENABLED async loggers, and the FASTLED_DBG/FASTLED_WARN/FASTLED_INFO/FASTLED_ERROR upper-case variants are NOT gated by this knob (separate concerns / separate users).

Tests

  • bash test fastled_core --cpp --clean — 1/1 passes at default verbosity
  • bash compile esp32s3 --examples Blink --platformio at default → matches master byte-for-byte
  • bash compile esp32s3 --examples Blink --platformio --defines FASTLED_LOG_VERBOSITY=0 → 620,384 B (the 33 KB drop above)

Cumulative Batch 1 + 2.3 picture

Stacking against the meta tracker:

Cumulative state firmware.bin
#2473 reported baseline (pre-Batch-1) 673,504 B
post-#2775 (item 1.1) 673,840 B (net ~0 — see #2773 comment)
post-#2778 (item 1.2 follow-up #2782) 657,680 B
master today (also includes #2786 item 1.4) 654,192 B
this PR (item 2.3) opt-in at level 0 620,384 B

Refs: #2773 #2473

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Introduced a new build-time logging verbosity configuration to give developers fine-grained control over which log levels are compiled into applications
    • Logging output can be completely disabled at compile time, allowing unused logging code to be stripped from the binary
    • Logging expressions remain type-checked even when logging is disabled, ensuring safer code

…2773 item 2.3)

Adds the verbosity tier described in the #2773 binary-size tracker. The
default (level 1) preserves the current `FL_WARN` / `FL_INFO` /
`FL_ERROR` / `FL_PRINT` behavior — full sstream-based formatting with
the file + line + severity prefix. Setting `FASTLED_LOG_VERBOSITY=0`
turns each of those macros into a type-checked no-op (`do { if (false)
{ (void)(fl::sstream_noop() << X); } } while (0)`), so:

- The merged `.str1.1` rodata pool that previously held every call
  site's `__FILE__` + `__LINE__` + " WARN: " + user-message literal
  goes away — the optimizer drops the `if (false)` branch before
  `--gc-sections` ever sees the literal references.
- User stream expressions stay type-checked, so a future build that
  flips back to level 1 doesn't surface fresh compile errors.
- Side-effects in `FL_WARN("…" << ++counter)` are *not* preserved —
  consistent with the documented contract of logging macros across the
  Arduino ecosystem (callers should keep diagnostics pure).
- `FASTLED_NO_LOG=1` is honored: it forces `FASTLED_LOG_VERBOSITY=0`
  so existing opt-out scripts keep working with the new gate.

## Empirical savings on ESP32-S3 Blink (PlatformIO + IDF 5.4)

| Build flags | `firmware.bin` |
|---|---:|
| master baseline (verbosity defaults to 1) | 654,192 B |
| `-DFASTLED_LOG_VERBOSITY=0` | **620,384 B** |

Net: **–33,808 B (–33 KB, –5.2 %)**. Matches the meta-tracker's
20–40 KB projection. The win is real-binary, not theoretical, because
every `FL_WARN`/`FL_INFO`/`FL_ERROR`/`FL_PRINT` call site bakes its
strings into the sketch translation unit; collapsing them all is the
only way to shrink the merged string pool that #2773 measured at
~58 KB on a stock Blink.

## Tests

- [x] `bash test fastled_core --cpp --clean` — 1/1 passes at default
  verbosity (level 1, current behavior)
- [x] `bash compile esp32s3 --examples Blink --platformio` at default →
  matches master byte-for-byte (no regression)
- [x] `bash compile esp32s3 --examples Blink --platformio --defines
  FASTLED_LOG_VERBOSITY=0` → 620,384 B (the 33 KB drop above)

Refs: #2773 #2473

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces FASTLED_LOG_VERBOSITY, a build-time configuration knob for controlling logging output across the FastLED library. When verbosity is disabled (FASTLED_LOG_VERBOSITY = 0, set automatically when FASTLED_NO_LOG is defined), all logging macros compile to type-checked no-ops. When enabled with sufficient memory, macros emit formatted output with file/line information.

Changes

Logging Verbosity Gating

Layer / File(s) Summary
Verbosity Configuration Knob
src/fl/log/log.h
Introduces FASTLED_LOG_VERBOSITY configuration (default 1, forced to 0 when FASTLED_NO_LOG is set), with documentation of release/no-op/verbose levels.
Logging Macro Gating and No-op Behavior
src/fl/log/log.h
Updates FL_ERROR, FL_WARN, FL_INFO, and FL_PRINT macros (and variants) to gate on SKETCH_HAS_LARGE_MEMORY && FASTLED_LOG_VERBOSITY > 0; disabled paths now use if (false) + fl::sstream_noop() to type-check expressions while compiling to no-ops.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • FastLED/FastLED#2751: Directly affects logging paths that switch from esp_rom_printf calls, making the new FASTLED_LOG_VERBOSITY gating mechanism relevant to downstream ESP32 logging implementations.

Poem

🐰 A config knob, so fine and true,
Makes logging dance at runtime's cue—
When verbosity drops to zero's call,
Type-checks stay strong, no-ops enthrall!
Dead code stripped, the firmware's lean,
Cleaner builds than ever seen.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: introducing a FASTLED_LOG_VERBOSITY release knob that enables significant binary size savings (33 KB). It directly matches the primary objective of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/2773-log-verbosity-knob

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/fl/log/log.h`:
- Around line 54-61: Replace the Unicode em-dash characters (U+2014) used in the
level descriptions comments (the lines starting with "0 — Release", "1 —
Default", and "2 — Verbose" in src/fl/log/log.h) with ASCII hyphens (-); ensure
the comments now read "0 - Release", "1 - Default", "2 - Verbose" and save the
file with 7-bit ASCII encoding so the header complies with the project's C++
source ASCII-only rule.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 63bfd51e-03b0-48e0-9843-f207188601e8

📥 Commits

Reviewing files that changed from the base of the PR and between 787de45 and b9e215f.

📒 Files selected for processing (1)
  • src/fl/log/log.h

Comment thread src/fl/log/log.h
Comment on lines +54 to +61
// 0 — Release: FL_WARN/FL_INFO/FL_ERROR/FL_PRINT expand to type-checked
// no-ops (`if (false) sstream_noop() << X`). Format strings and
// sstream operator chains disappear; the linker garbage-collects the
// merged string pool. Best for shipping firmware where Serial isn't
// used at runtime.
// 1 — Default (current behavior): full stream formatting on platforms
// where SKETCH_HAS_LARGE_MEMORY allows it.
// 2 — Verbose: reserved for future use; currently behaves like 1.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Replace Unicode em-dashes with ASCII hyphens.

Lines 54, 59, and 61 use Unicode em-dash characters (U+2014 "—") in the level descriptions, violating the strict 7-bit ASCII requirement for C++ source files.

As per coding guidelines, all source code in .h/.cpp/.hpp files must be strictly 7-bit ASCII (no emoji or Unicode punctuation in comments/strings).

🔧 Proposed fix
-//   0  — Release: FL_WARN/FL_INFO/FL_ERROR/FL_PRINT expand to type-checked
+//   0  - Release: FL_WARN/FL_INFO/FL_ERROR/FL_PRINT expand to type-checked
 //        no-ops (`if (false) sstream_noop() << X`). Format strings and
 //        sstream operator chains disappear; the linker garbage-collects the
 //        merged string pool. Best for shipping firmware where Serial isn't
 //        used at runtime.
-//   1  — Default (current behavior): full stream formatting on platforms
+//   1  - Default (current behavior): full stream formatting on platforms
 //        where SKETCH_HAS_LARGE_MEMORY allows it.
-//   2  — Verbose: reserved for future use; currently behaves like 1.
+//   2  - Verbose: reserved for future use; currently behaves like 1.

Based on coding guidelines: "Keep all source code strictly 7-bit ASCII in .h/.cpp/.hpp files (no emoji or Unicode punctuation in comments/strings)" (agents/docs/cpp-standards.md).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// 0 — Release: FL_WARN/FL_INFO/FL_ERROR/FL_PRINT expand to type-checked
// no-ops (`if (false) sstream_noop() << X`). Format strings and
// sstream operator chains disappear; the linker garbage-collects the
// merged string pool. Best for shipping firmware where Serial isn't
// used at runtime.
// 1 — Default (current behavior): full stream formatting on platforms
// where SKETCH_HAS_LARGE_MEMORY allows it.
// 2 — Verbose: reserved for future use; currently behaves like 1.
// 0 - Release: FL_WARN/FL_INFO/FL_ERROR/FL_PRINT expand to type-checked
// no-ops (`if (false) sstream_noop() << X`). Format strings and
// sstream operator chains disappear; the linker garbage-collects the
// merged string pool. Best for shipping firmware where Serial isn't
// used at runtime.
// 1 - Default (current behavior): full stream formatting on platforms
// where SKETCH_HAS_LARGE_MEMORY allows it.
// 2 - Verbose: reserved for future use; currently behaves like 1.
🤖 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` around lines 54 - 61, Replace the Unicode em-dash
characters (U+2014) used in the level descriptions comments (the lines starting
with "0 — Release", "1 — Default", and "2 — Verbose" in src/fl/log/log.h) with
ASCII hyphens (-); ensure the comments now read "0 - Release", "1 - Default", "2
- Verbose" and save the file with 7-bit ASCII encoding so the header complies
with the project's C++ source ASCII-only rule.

@zackees

zackees commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

Closing in favor of #2791, which is strictly better:

  • Also gates FL_DBG (mine only covered FL_WARN/FL_INFO/FL_ERROR/FL_PRINT). That extra coverage is the bulk of the +10 KB gap between my measured –33 KB and their measured –43 KB.
  • Cleaner intermediate FASTLED_LOG_RUNTIME_ENABLED macro vs my repeated SKETCH_HAS_LARGE_MEMORY && FASTLED_LOG_VERBOSITY > 0 condition at every gate site.
  • Pins FASTLED_TESTING to verbosity ≥ 1 unconditionally so host unit tests always get the diagnostic stream regardless of how the build flag is set.

The only thing this PR has that #2791 doesn't is the if (false) { (void)(fl::sstream_noop() << X); } form for type-checking expressions at level 0 — marginal benefit, easy to layer on top of #2791 in a follow-up if anyone hits a missed compile error after toggling the knob.

No reason to land two competing implementations.

@zackees zackees closed this Jun 5, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
@zackees
zackees deleted the feat/2773-log-verbosity-knob branch November 17, 2026 07:12
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.

1 participant