Skip to content

perf(channels): gate addDriver capStr builder behind FASTLED_HAS_DBG (#2773 iter 6) - #2833

Merged
zackees merged 1 commit into
masterfrom
feat/2773-iter6-bloat-trim
Jun 5, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2773-iter6-bloat-trim

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

The capability-string builder in ChannelManager::addDriver exists only to feed the trailing FL_DBG(\"...caps: \" << capStr.c_str() ...) line. On FASTLED_HAS_DBG=0 builds (default SKETCH_HAS_LARGE_MEMORY=0 path AND any -DFASTLED_LOG_VERBOSITY=0 opt-in build), FL_DBG itself already expands to do { if (false) {...} } while (0), but the fl::string capStr allocation, two if branches, and the if (capStr.empty()) capStr = \"NONE\" fallback above it still emitted code — the optimizer wasn't reliably DCE'ing them through the if (false) form.

Wrapping the whole block in #if FASTLED_HAS_DBG makes the elision explicit so the linker drops it without depending on DCE behavior. Same approach attempted on a previously-closed parallel PR (#2832); reopening it standalone with a fresh measurement against current master.

Measured on ESP32-S3 Blink (PlatformIO + IDF 5.4)

Build firmware.bin Δ
master (default verbosity) 661,408 B —
this PR (default verbosity) 661,408 B 0
master + -DFASTLED_LOG_VERBOSITY=0 616,848 B —
this PR + -DFASTLED_LOG_VERBOSITY=0 616,384 B −464 B

Zero risk at default (the gate is true when FASTLED_HAS_DBG=1, so the inside-the-#if code is identical to today). The −464 B on the opt-in slim build is real because the fl::string ops above the FL_DBG were being kept by the compiler even though FL_DBG itself was a no-op.

Refs: #2773

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Optimized debug code compilation to reduce binary size when debug features are disabled.

…2773 iter 6)

The capability-string builder in `ChannelManager::addDriver` exists only
to feed the trailing `FL_DBG("...caps: " << capStr.c_str() ...)` line.
On `FASTLED_HAS_DBG=0` builds (default `SKETCH_HAS_LARGE_MEMORY=0` path
AND any `-DFASTLED_LOG_VERBOSITY=0` opt-in) the `FL_DBG` already expands
to `do { if (false) {...} } while (0)`, but the `fl::string capStr`
allocation, two `if` branches, and an `if (empty) capStr = "NONE"`
fallback above it still emitted code — the optimizer wasn't reliably
DCE'ing them through the `if (false)` form.

Wrapping the whole block in `#if FASTLED_HAS_DBG` makes the elision
explicit so the linker drops it without depending on DCE behavior.

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

| Build | `firmware.bin` | Δ |
|---|---:|---:|
| master (default verbosity) | 661,408 B | — |
| this PR (default verbosity) | 661,408 B | **0** |
| master + `-DFASTLED_LOG_VERBOSITY=0` | 616,848 B | — |
| this PR + `-DFASTLED_LOG_VERBOSITY=0` | 616,384 B | **−464 B** |

Zero risk at default (the gate is true when `FASTLED_HAS_DBG=1`, so the
inside-the-#if code is identical to today). The −464 B on the opt-in
slim build is real because the `fl::string` ops above the FL_DBG were
being kept by the compiler even though FL_DBG itself was a no-op.

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

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Need the big picture first? Review this PR in Change Stack to see what changed before going file by file.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 24dfa089-4ba6-4f1e-96fc-e90b9e595056

📥 Commits

Reviewing files that changed from the base of the PR and between e2772c9 and ea96b37.

📒 Files selected for processing (1)
  • src/fl/channels/manager.cpp.hpp

📝 Walkthrough

Walkthrough

The PR adds preprocessor guards around debug-only capability-string construction in ChannelManager::addDriver(). When FASTLED_HAS_DBG is disabled, the getCapabilities() call and string allocation are no longer compiled, reducing binary size and eliminating unused code.

Changes

Debug logging guard

Layer / File(s) Summary
ChannelManager debug logging guard
src/fl/channels/manager.cpp.hpp
The capability-string construction and FL_DBG logging statement are wrapped with #if FASTLED_HAS_DBG / #endif preprocessor directives, ensuring debug-only code is only compiled when debug logging is enabled.

Possibly related PRs

  • FastLED/FastLED#2791: The main PR's ChannelManager::addDriver() now avoids building the capStr argument behind an FASTLED_HAS_DBG-guarding FL_DBG call, which is directly impacted by the retrieved PR's re-gating/disable of FL_DBG via FASTLED_LOG_VERBOSITY.

Poem

🐰 With guards so fine, #if and #endif dance,
Debug code sleeps when logging's not in trance,
No capStr built in lean production ground,
Binary slims while logic stays sound!

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 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: wrapping the debug capability-string builder in addDriver behind the FASTLED_HAS_DBG preprocessor guard, which directly aligns with the changeset's primary objective of performance optimization through debug-only code gating.
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-iter6-bloat-trim

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.

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