Skip to content

refactor(channels): extract showPixels cold-path errors + gate addDriver capStr build (#2773 iter 3) - #2832

Closed
zackees wants to merge 1 commit into
masterfrom
memhunt/2773-iter-3-more-extraction
Closed

zackees wants to merge 1 commit into
masterfrom
memhunt/2773-iter-3-more-extraction

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Two more applications of the noinline-helper pattern from iter 2 (PR #2826), targeting the next two FastLED-owned hot symbols on the esp32dev Blink build.

Channel::showPixels (4243 B → expected ~3000 B)

Three multi-line FL_ERROR(... << ...) chains in showPixels, each behind a one-shot guard (mBusWarned, mDisabledDriverWarned), were inlining ~10 `operator<<` instantiations into the path that runs every frame:

Moved into three noinline static helpers in the existing anonymous namespace just above showPixels:

  • `emitTypedBusNotInstantiatedError(name, busKey)`
  • `emitTypedBusChipsetMismatchError(name, busKey)`
  • `emitDisabledDriverError(name, driverName, exclusive)`

Pure code motion — same rodata, same FL_ERROR severity, same one-shot guard semantics.

ChannelManager::addDriver (2367 B)

The capability-string builder (`capStr`) at the bottom of addDriver existed only to populate the trailing FL_DBG line. On release builds (`FASTLED_HAS_DBG == 0`) FL_DBG is no-op, but the `fl::string` allocation and the two branch-checks still ran and still emitted code. Wrap the whole block in `#if FASTLED_HAS_DBG`.

  • On default ESP32 builds (`SKETCH_HAS_LARGE_MEMORY` → `FASTLED_HAS_DBG=1`): no-op.
  • On `-DFASTLED_LOG_VERBOSITY=0` / `-DFASTLED_DISABLE_DBG=1` builds: removes the dead code entirely.

Verification status

My local fbuild esp32dev infrastructure is currently broken (zccache daemon won't start — all native + ESP32 builds fail with `zccache[err]: cannot connect to daemon`), so size measurements rely on CI. The pattern is the same one that landed in iter 2 (PR #2826: createChannel −28%, already merged on master with no regressions); this PR extends the same mechanical refactor to two adjacent symbols.

Test plan

Refs #2773 (memory-hunt loop, iter 3).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Optimized diagnostic logging performance by streamlining error reporting paths.
    • Improved build efficiency with conditional compilation for debug capabilities.

…ver capStr build (#2773 iter 3)

Two more applications of the noinline-helper pattern from iter 2 (PR #2826),
chasing the next two FastLED-owned hot symbols in the esp32dev Blink build:

## Channel::showPixels — was 4243 B (#2 in the symbol table)

Three multi-line `FL_ERROR(... << ...)` chains in showPixels, each behind a
one-shot guard (`mBusWarned`, `mDisabledDriverWarned`), inlined ~10
`operator<<` instantiations into the hot path that runs every frame:

- typed-Bus-not-instantiated diagnostic (#2455 / #2459)
- typed-Bus-chipset-mismatch diagnostic
- disabled-driver silent-drop diagnostic (#2517)

Moved into three `noinline static` helpers in the existing anonymous
namespace just above showPixels:

- `emitTypedBusNotInstantiatedError(name, busKey)`
- `emitTypedBusChipsetMismatchError(name, busKey)`
- `emitDisabledDriverError(name, driverName, exclusive)`

Pure code motion — same rodata, same FL_ERROR severity, same one-shot
guard semantics. Each guard still fires exactly once per channel
lifetime; the helper call is on the cold path.

## ChannelManager::addDriver — was 2367 B (#5 in the symbol table)

The capability-string builder (`capStr`) at the bottom of addDriver
existed *only* to populate the trailing FL_DBG line. On release builds
(`FASTLED_HAS_DBG == 0`) FL_DBG is no-op, but the `fl::string` allocation
and the two branch-checks (`supportsClockless` / `supportsSpi`) still ran
and still emitted code. Wrap the entire block (capStr build + FL_DBG)
in `#if FASTLED_HAS_DBG`. On default ESP32 builds (SKETCH_HAS_LARGE_MEMORY
→ FASTLED_HAS_DBG=1) this is a no-op; on `-DFASTLED_LOG_VERBOSITY=0` and
`-DFASTLED_DISABLE_DBG=1` builds it removes the dead code entirely.

## Verification

Local fbuild esp32dev build infrastructure (zccache daemon) is broken on
my workstation today, so size measurements rely on CI. Pattern is the
same one that landed in iter 2 (PR #2826: createChannel -28%). Iter 2 is
already merged on master with no regressions; this PR extends the same
mechanical refactor to two adjacent symbols.

Refs #2773 (memory-hunt loop, iter 3).

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

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Too much diff to scan? Review this PR in Change Stack to start with the highest-impact changes.

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: f534a24b-ad37-413d-9a9b-10204407be85

📥 Commits

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

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

📝 Walkthrough

Walkthrough

This PR refactors diagnostic error emissions in Channel::showPixels() into noinline helper functions to reduce hot-path code size, and gates debug capability-string construction in ChannelManager::addDriver() behind FASTLED_HAS_DBG to reduce binary footprint when debug logging is disabled.

Changes

Performance and size optimization

Layer / File(s) Summary
Channel::showPixels() error helper functions and call sites
src/fl/channels/channel.cpp.hpp
Three __attribute__((noinline)) static helpers emit typed-bus and disabled-driver error diagnostics out of the hot path. Existing error detection logic calls emitTypedBusChipsetMismatchError() and emitDisabledDriverError() instead of inline FL_ERROR chains, preserving one-shot guard logic and conditional exclusive-driver-name inclusion.
ChannelManager capability-string debug-only compilation
src/fl/channels/manager.cpp.hpp
Capability-string assembly is wrapped in #if FASTLED_HAS_DBG guard, preventing capStr construction and intermediate fl::string work when debug logging is disabled, while driver addition and priority sorting remain unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • FastLED/FastLED#2473: Directly addresses the same code-level contributors to the ESP32-S3 size regression by extracting heavy Channel::showPixels() logging and gating ChannelManager debug capability-string assembly behind FASTLED_HAS_DBG.

Possibly related PRs

Poem

🐰 In channels deep, the errors lay so long,
Cold paths now thaw—helpers make them strong,
One-shot guards preserve the steady beat,
While debug gates trim the binary sheet. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: extracting showPixels cold-path errors into helper functions and conditionally gating the addDriver capability-string build behind a debug flag.
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 memhunt/2773-iter-3-more-extraction
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch memhunt/2773-iter-3-more-extraction

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.

@zackees

zackees commented Jun 5, 2026

Copy link
Copy Markdown
Member Author

Closing — most of this work was shipped in parallel via #2830 (showPixels cold-path split + FL_NO_INLINE migration). The two pieces this PR has that #2830 didn't (emitDisabledDriverError and the #if FASTLED_HAS_DBG gate on ChannelManager::addDriver's capStr builder) are small enough (~couple hundred bytes) that a rebase round trip isn't worth the churn vs just reopening them in a follow-up if the binary-size loop resumes. The loop is paused per #2773's latest comment — remaining items need maintainer-driven coordination, not auto-iteration.

@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 added a commit that referenced this pull request Jun 6, 2026
… into FL_NO_INLINE helper (#2773 follow-up to #2832)

The two-branch `FL_ERROR(... << ...)` chain in `Channel::showPixels`
that fires when a bound driver has been runtime-disabled (typically
by `FastLED.setExclusiveDriver<OtherBus>()`) was still inlined into
the hot path. The branch is one-shot (`mDisabledDriverWarned`) and
unreachable in the steady state, so the ~10 `operator<<`
instantiations were pure cold-path bloat sitting in showPixels'
prologue/epilogue.

Move into an anonymous-namespace helper marked `FL_NO_INLINE` (per
the `bare_noinline_checker` introduced in #2830, not bare
`__attribute__((noinline))`), matching the shape the maintainer
adopted for `resolveDynamicDriver()` in PR #2830.

This is the leftover piece from PR #2832, which the maintainer
flagged in the closing comment as worth a follow-up:

> The two pieces this PR has that #2830 didn't (emitDisabledDriverError
> and the #if FASTLED_HAS_DBG gate on ChannelManager::addDriver's
> capStr builder) are small enough (~couple hundred bytes) that a
> rebase round trip isn't worth the churn vs just reopening them in
> a follow-up.

The `addDriver` capStr DBG gate piece of #2832 was independently
shipped by the maintainer as iter 6 (commit `ea96b373b5`,
`perf(channels): gate addDriver capStr builder behind FASTLED_HAS_DBG
(#2773 iter 6)`), so this rebase drops that half and keeps only the
unique `emitDisabledDriverError` extraction.

Refs #2773.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the memhunt/2773-iter-3-more-extraction 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