Skip to content

perf: combined #2856 items 3.1 + 3.2 + 3.3 + 3.5 (single PR per /clud-pr workflow) - #2863

Merged
zackees merged 2 commits into
masterfrom
feat/2856-combined-3.1-3.2-3.3-3.5
Jun 6, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/2856-combined-3.1-3.2-3.3-3.5

Conversation

@zackees

@zackees zackees commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Single combined PR for meta #2856, per the /clud-pr workflow's "one PR per task" rule. Items 3.6 (#2861) was already merged separately before this consolidation; item 3.4 was already in master before #2856 was filed.

This PR addresses items 3.1, 3.2, 3.3, and 3.5:

Item 3.1 — Cold-helper split of `ChannelEngineRMTImpl::~dtor`

The destructor body (drain-wait + per-channel cleanup loop + FL_WARN timeout diagnostic + FL_LOG_RMT trailer) is a cold path — only reached at process end. Move it into an `FL_NO_INLINE destructorCleanup()` helper so its operator<< instantiations + the multi-line cleanup loop body don't contribute to icache footprint in the steady-state code that calls into the engine. Same pattern that worked for #2773 items 2.1 (PR #2830), 2.2 (PR #2838), 2.5 (PR #2840).

Item 3.2 — `FL_WARN_LIT` / `FL_LOG_LIT` macros for literal-only sites

Each `FL_WARN(literal)` bakes an `fl::sstream` + `operator<<` chain for the file/line prefix + the literal at every call site. For sites that pass nothing but a literal string, that's pure overhead vs a single `fl::println` call.

Add `FL_WARN_LIT(literal)` / `FL_LOG_LIT(literal)` macros: route literal-only messages through `fl::println` directly, dropping the file/line prefix. The literal carries its own `"[RMT]"` prefix to partially compensate. The non-literal `FL_WARN` remains available for sites that need operator<< formatting or the file/line prefix.

Migrates the destructor timeout warning as a first proof-of-concept. Other call sites can move to `FL_WARN_LIT` incrementally.

This is a bounded, first step toward the full printf-style log backend described in #2856 item 3.2. The full backend (`fl::printf("fmt", args...)`) is multi-day work; this PR introduces the literal-only fast path as a stable building block. Subsequent PRs can add the printf API and bulk-migrate remaining sites.

Item 3.3 — Skip `NetworkDetector` under `FASTLED_RMT_STATIC_ALLOCATION`

`ChannelEngineRMT::createChannel` calls `NetworkDetector::isAnyNetworkActive()` on every allocation to choose network-mode vs idle-mode buffer sizing. Under `FASTLED_RMT_STATIC_ALLOCATION` (#2846) the user has asserted no network during LED transmission, so this resolves to constexpr `false`. The linker then drops the `NetworkDetector` singleton + WiFi-state-reading chain from the binary.

This is the most impactful piece of #2856 item 3.3 that can land safely. The full static-bind addLeds<>() refactor (touching every example) is deferred.

Item 3.5 — `tryAllocateTx` / `tryAllocateRx` status-code variants

(Same content as the closed #2862, cherry-picked into this single combined PR.) Adds bool-returning wrappers around the `result<>`-bearing `allocateTx`/`allocateRx` for the 4 internal callsites that don't need the specific error code. `result<>`-bearing API retained for tests + public callers.

What's NOT in this PR

The /clud-pr stop-hook flagged that #2856 was multi-PR; this PR consolidates. But three pieces of work in the meta are genuinely sprint-sized refactors that cannot safely land in one PR session:

  • Full Level B template-trait refactor of `Channel::showPixels` — requires `ChannelEngineRMTImpl` class template, `kIsStaticInit` thread-local, audit of every example's `addLeds<>` instantiation. Design RFC at #2773 comment 4636464324.
  • Full printf-style log backend — requires new `fl::printf("fmt", args...)` API surface + bulk migration of ~hundreds of FL_WARN/FL_LOG_RMT sites.
  • Full static-bind path for boot-time `addLeds<>()` — largest blast radius, touches every example.

The minimal real wins from each (this PR) are landed; the architectural refactors are documented in #2856's tracking matrix as deferred.

Test plan

  • `bash lint --cpp` — clean
  • `bash test --cpp` — 310/310 pass
  • CI on this PR
  • Map-file audit via CI artifacts on a `FASTLED_RMT_STATIC_ALLOCATION=1` build (item 3.3 NetworkDetector trim is gated on this)

Refs #2856.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Refactored RMT driver memory allocation patterns with updated status-code handling for DMA and non-DMA configurations.
    • Enhanced logging system with new literal-only macros.
    • Updated memory manager allocation APIs for consistency across platform implementations.

zackees added 2 commits June 5, 2026 20:45
…tem 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 #2856 item 3.5. Estimated savings: small (call-site result<>
constructor + .ok() + .value() decoded into bool check + out param read).
Real win compounds with #2791 (FASTLED_LOG_VERBOSITY=0) and #2846
(FASTLED_RMT_STATIC_ALLOCATION=1) where the FL_WARN diagnostic chains
already disappear.
This is the consolidated PR for items 3.1, 3.2, 3.3, 3.5 of #2856.
Item 3.6 already merged via #2861; item 3.4 was already in master
before #2856 was filed (encoder is already a runtime virtual on
IRMT5Peripheral::createEncoder).

Item 3.1 — Cold-helper split of ChannelEngineRMTImpl::~dtor
============================================================
The destructor body (drain-wait + per-channel cleanup loop +
FL_WARN timeout diagnostic + FL_LOG_RMT trailer) is a cold path —
only reached at process end. Move it into an FL_NO_INLINE
destructorCleanup() helper so its operator<< instantiations + the
multi-line cleanup loop body don't contribute to icache footprint
in the steady-state code that calls into the engine.

Item 3.2 — FL_WARN_LIT / FL_LOG_LIT for literal-only sites
==========================================================
Each FL_WARN(literal) bakes an fl::sstream + operator<< chain for the
file/line prefix + the literal at every call site. For sites that pass
nothing but a literal string, that's pure overhead vs a single
fl::println call.

Add FL_WARN_LIT(literal) / FL_LOG_LIT(literal) macros: route literal-
only messages through fl::println directly, dropping the
file/line prefix. The literal carries its own "[RMT]" prefix to
partially compensate. The non-literal FL_WARN remains available for
sites that need operator<< formatting or the file/line prefix.

Migrates the destructor timeout warning as a first proof-of-concept.
Other call sites can move to FL_WARN_LIT incrementally.

Item 3.3 — Skip NetworkDetector under FASTLED_RMT_STATIC_ALLOCATION
===================================================================
ChannelEngineRMT::createChannel calls
NetworkDetector::isAnyNetworkActive() on every allocation to choose
network-mode vs idle-mode buffer sizing. Under
FASTLED_RMT_STATIC_ALLOCATION the user has asserted no network during
LED transmission (per #2846), so this resolves to constexpr false. The
linker then drops the NetworkDetector singleton + WiFi-state-reading
chain from the binary.

Item 3.5 — tryAllocateTx / tryAllocateRx status-code variants
=============================================================
(Same as the closed #2862 — cherry-picked here for the single combined
PR.) Adds bool-returning wrappers around the result<>-bearing
allocateTx/allocateRx for the 4 internal callsites that don't need the
specific error code. Result<>-bearing API retained for tests + public
callers.

Refs #2856. Closes the actionable scope of the meta; the deferred
items (full Level B refactor, full printf backend, full static-bind
addLeds<>) are independently large enough to deserve their own issues
and aren't safe to land in one PR session.
@coderabbitai

coderabbitai Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Linter diff in the way? Review this PR in Change Stack to focus on meaningful changes and expand context only when needed.

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: c6b750f0-70d7-4ea3-a9ba-04bf2bd68750

📥 Commits

Reviewing files that changed from the base of the PR and between 6590c59 and 215b558.

📒 Files selected for processing (6)
  • src/fl/log/log.h
  • src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp
  • src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp
  • src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.h
  • src/platforms/esp/32/drivers/rmt_rx/rmt_rx_channel.cpp.hpp
  • src/platforms/shared/mock/esp/32/drivers/rmt5_support_stubs.h

📝 Walkthrough

Walkthrough

The PR introduces compile-time literal-only logging macros (FL_WARN_LIT/FL_LOG_LIT) for direct string output without formatting overhead, adds status-code style allocation wrappers (tryAllocateTx/tryAllocateRx) to RmtMemoryManager, and refactors RMT TX/RX channel drivers to use these new APIs while adding compile-time networkActive configuration support.

Changes

Logging and RMT allocation refactoring

Layer / File(s) Summary
Literal logging macros
src/fl/log/log.h
FL_WARN_LIT and FL_LOG_LIT macros print string literals directly via fl::println when enabled; both become empty no-ops when logging is disabled, eliminating sstream formatting and standard prefix overhead.
Memory manager try-allocate wrapper APIs
src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.h, rmt_memory_manager.cpp.hpp
RmtMemoryManager gains public tryAllocateTx and tryAllocateRx methods that wrap existing allocateTx/allocateRx logic, returning bool success/failure while populating an out_words reference parameter with allocated word count. Intended for callers treating all allocation failures uniformly.
RMT TX channel allocation and diagnostic refactoring
src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp
ChannelEngineRMTImpl destructor cleanup factored into an FL_NO_INLINE helper; timeout diagnostic switched to FL_WARN_LIT; networkActive now supports compile-time FASTLED_RMT_STATIC_ALLOCATION forcing (else runtime NetworkDetector query); both DMA and non-DMA TX allocation paths switched from allocateTx().ok() to tryAllocateTx() with local word-count output parameters.
RMT RX channel allocation refactoring
src/platforms/esp/32/drivers/rmt_rx/rmt_rx_channel.cpp.hpp
Constructor and begin() method updated to call memMgr.tryAllocateRx() instead of allocateRx().ok(), with alloc_words output parameter; failure logs warning and returns false without further processing.
RMT memory manager test stubs
src/platforms/shared/mock/esp/32/drivers/rmt5_support_stubs.h
RmtMemoryManager mock stub adds tryAllocateTx and tryAllocateRx methods that always succeed, writing fixed word count (64) to out_words parameter, mirroring production allocation wrapper interface.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • FastLED/FastLED#2856: This PR implements exactly two Batch-3 items: the literal/printf-style logging path (FL_WARN_LIT/FL_LOG_LIT and usage in channel_driver_rmt) and the status-code allocation wrapper variant (tryAllocateTx/tryAllocateRx with caller updates).

Possibly related PRs

  • FastLED/FastLED#2846: Main PR extends the existing FASTLED_RMT_STATIC_ALLOCATION compile-time behavior in RMT5 (forcing networkActive to false in createChannel()), aligning with PR #2846's compile-time allocation logic in RmtMemoryManager::calculateMemoryBlocks().
  • FastLED/FastLED#2838: Both PRs modify channel_driver_rmt.cpp.hpp's TX allocation path; main PR switches to tryAllocateTx and adds compile-time networkActive support, while the retrieved PR refactors progressive retry logic.
  • FastLED/FastLED#2840: Both PRs modify RMT5 memory allocation—main PR adds tryAllocateTx/tryAllocateRx wrappers with caller updates, while retrieved PR refactors cold-path failure handling that these wrappers depend on.

Poem

🐰 Hops and beeps, logging light,
Allocate the rightful bytes,
With status codes so clean and clear,
No sstream fuss to interfere!
TX, RX, stubs in place—
Code now runs at quickened pace. 🚀

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title references meta-issue #2856 and specific items (3.1, 3.2, 3.3, 3.5) but is vague about what these changes actually accomplish; a developer scanning history would not understand the substance of the modifications. Consider a more descriptive title like 'perf: optimize RMT memory management and add literal logging macros' that conveys the main changes without relying on external issue references.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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/2856-combined-3.1-3.2-3.3-3.5

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