Skip to content

perf(rmt5): tryAllocateTx/tryAllocateRx status-code variants (#2856 item 3.5) - #2862

Closed
zackees wants to merge 1 commit into
masterfrom
feat/2856-3.5-result-to-statuscode
Closed

zackees wants to merge 1 commit into
masterfrom
feat/2856-3.5-result-to-statuscode

Conversation

@zackees

@zackees zackees commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Second PR against meta #2856. Implements 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).

Migrated the 4 internal sites to the new API. Mock `RmtMemoryManager` (`rmt5_support_stubs.h`) gets matching always-succeeds stubs so the host test build links.

Stack vs the rest of meta #2856

This is the second PR (after #2861, item 3.6). Status of the remaining items:

The clud-pr skill's "one PR per task" rule conflicts with #2856 being a meta covering 6 architecturally-separate items. The split chosen here: ship the bounded items (3.5, 3.6) immediately as their own PRs, defer the multi-day items (3.1, 3.2, 3.3) for explicit follow-up rather than landing speculative scaffolding.

Test plan

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Updated internal memory allocation handling for ESP32 RMT drivers to improve code consistency and reliability across transmit and receive channels.

…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.
@coderabbitai

coderabbitai Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Wondering what really moved? Review this PR in Change Stack to inspect semantic changes, definitions, and references.

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

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: 3aebfa9b-4833-4f27-9cca-8afe6d0f8a42

📥 Commits

Reviewing files that changed from the base of the PR and between 6590c59 and 9661f30.

📒 Files selected for processing (5)
  • 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

This PR adds status-code allocation variants (tryAllocateTx, tryAllocateRx) to RmtMemoryManager that return boolean success and populate output word-count parameters, then migrates RMT5 TX and RX channel drivers from result-based allocation calls to these new variants. Mock stubs are updated correspondingly.

Changes

RMT Memory Allocation API Refactoring

Layer / File(s) Summary
Memory manager try-allocation API contract
src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.h, src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp
RmtMemoryManager adds tryAllocateTx and tryAllocateRx public methods that wrap existing allocation functions, return boolean success, and populate an output size_t& out_words parameter with the allocated word count when successful.
TX channel memory allocation migration
src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp
DMA and non-DMA allocation paths in RMT5 TX channel now use tryAllocateTx(...) with boolean success checks and output parameters, replacing the prior result-object flow and removing the dependency on alloc_result.value().
RX channel memory allocation migration
src/platforms/esp/32/drivers/rmt_rx/rmt_rx_channel.cpp.hpp
RMT RX channel constructor pre-registration and begin() re-registration now use tryAllocateRx(...) with boolean outcomes controlling memory registration state and allocation failure behavior.
Mock stub allocation support
src/platforms/shared/mock/esp/32/drivers/rmt5_support_stubs.h
Test mock stubs add tryAllocateTx and tryAllocateRx methods that always succeed, writing 64 to the output word-count parameter and returning true.

Possibly related PRs

  • FastLED/FastLED#2838: Overlaps at RMT5 TX channel_driver_rmt.cpp.hpp memory-allocation recovery—this PR switches allocations to tryAllocateTx while #2838 factors the recovery loop into a helper.
  • FastLED/FastLED#2826: Both touch ChannelEngineRMTImpl::createChannel allocation failure paths in channel_driver_rmt.cpp.hpp—this PR changes to use tryAllocateTx while #2826 refactors warning/error messages into helpers.
  • FastLED/FastLED#2840: Related to RMT5 TX/RX memory allocation flow in RmtMemoryManager—perf(rmt5): split allocateTx fail-path into cold helper (#2773 item 2.5) #2840 refactors allocateTx failure handling while this PR adds try* wrappers that call the updated allocation functions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A status-code dance we now perform,
Out-params pass, no exceptions to transform,
Try-allocate flows through TX and RX alike,
Mock stubs succeed with every allocated strike,
Migration complete—the rabbit approves! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.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 describes the main change: adding tryAllocateTx and tryAllocateRx status-code variant APIs to improve performance by avoiding result<> construction/inspection at internal callsites.
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-3.5-result-to-statuscode

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 6, 2026

Copy link
Copy Markdown
Member Author

Consolidating into single combined PR per /clud-pr workflow's 'one PR per task' rule. New PR will include this commit + #2861 + items 3.1/3.2/3.3.

@zackees zackees closed this Jun 6, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 6, 2026
pull Bot pushed a commit to manmuqingshan/FastLED that referenced this pull request Jun 6, 2026
This is the consolidated PR for items 3.1, 3.2, 3.3, 3.5 of FastLED#2856.
Item 3.6 already merged via FastLED#2861; item 3.4 was already in master
before FastLED#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 FastLED#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 FastLED#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 FastLED#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.
@zackees
zackees deleted the feat/2856-3.5-result-to-statuscode 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