Skip to content

perf(rmt5): no-op free()/freeDMA() under FASTLED_RMT_STATIC_ALLOCATION (#2856 item 3.6) - #2861

Merged
zackees merged 1 commit into
masterfrom
feat/2856-3.6-static-alloc-fixed-ledger
Jun 6, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2856-3.6-static-alloc-fixed-ledger

Conversation

@zackees

@zackees zackees commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Summary

First PR against meta #2856. Implements item 3.6 in its smallest viable form.

Under `FASTLED_RMT_STATIC_ALLOCATION=1` (#2846) the user has asserted no `removeLeds()` / late `addLeds()`. The destructor of `ChannelEngineRMTImpl` still calls `memMgr.free()` / `memMgr.freeDMA()` on every channel at process end, but the ledger isn't meaningfully tracked under static mode so the work is dead — yet it still pulls `fl::vector_inlined::erase`, the `begin`/`end` iterator chain, and the multi-line `FL_LOG_RMT` / `FL_WARN` `operator<<` instantiations into the binary.

Skip both bodies under the macro:

```cpp
void RmtMemoryManager::free(u8 channel_id, bool is_tx) FL_NOEXCEPT {
#if FASTLED_RMT_STATIC_ALLOCATION
(void)channel_id; (void)is_tx;
#else
// ... existing ledger update + erase loop + FL_LOG_RMT ...
#endif
}
```

Default behavior (`FASTLED_RMT_STATIC_ALLOCATION=0`) is unchanged.

Scope vs the rest of meta #2856

This PR ships item 3.6 only. Items 3.1, 3.2, 3.3, 3.5 are scoped for their own PRs (multi-day / large-blast-radius). Item 3.4 (encoder dedup) was already done in the existing RMT5 architecture before #2856 was filed — the encoder is a runtime virtual on `IRMT5Peripheral::createEncoder(const ChipsetTiming&, u32)`, not templated per-chipset. Updating the tracking matrix on #2856 to reflect this.

Test plan

Refs #2856 item 3.6.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Optimized memory management operations for ESP32 devices when static memory allocation is enabled, reducing runtime overhead and improving system efficiency on embedded platforms.

#2856 item 3.6)

Under FASTLED_RMT_STATIC_ALLOCATION=1 (#2846) the user has asserted no
removeLeds() / late addLeds(). The destructor of ChannelEngineRMTImpl
still calls memMgr.free() / memMgr.freeDMA() on every channel at
process end, but the ledger isn't meaningfully tracked under static
mode so the work is dead — yet it still pulls
fl::vector_inlined::erase, the begin/end iterator chain, and the
multi-line FL_LOG_RMT / FL_WARN operator<< instantiations into the
binary.

Skip both bodies under the macro. Default behavior
(FASTLED_RMT_STATIC_ALLOCATION=0) is unchanged.

Refs #2856 item 3.6. Stacks on #2846 (FASTLED_RMT_STATIC_ALLOCATION
opt-in macro). Estimated savings: ~few hundred bytes additional
when both #2791 (FASTLED_LOG_VERBOSITY=0) and #2846 are also opted in.
@coderabbitai

coderabbitai Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Looking for one thing? Review this PR in Change Stack to search files, summaries, diffs, and code without losing your place.

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: cbf77311-de67-480f-a0f4-c6c3790ebd18

📥 Commits

Reviewing files that changed from the base of the PR and between 4c31af9 and 8dabb2f.

📒 Files selected for processing (1)
  • src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp

📝 Walkthrough

Walkthrough

This PR makes RmtMemoryManager::free() and freeDMA() conditional no-ops when FASTLED_RMT_STATIC_ALLOCATION is enabled, allowing static-allocation builds to skip dynamic memory cleanup and allocation tracking operations.

Changes

RMT Static Allocation Memory Management

Layer / File(s) Summary
RmtMemoryManager no-op stubs for static allocation
src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp
free() and freeDMA() methods are wrapped in #ifdef FASTLED_RMT_STATIC_ALLOCATION preprocessor blocks to become empty no-ops in that configuration, skipping allocation lookup, word deallocation, logging, DMA diagnostics, and state cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

  • #2856: Both changes align with the Batch 3.6 goal to remove dynamic allocation machinery when static allocation is enabled.

Possibly related PRs

  • FastLED/FastLED#2846: Both PRs gate RmtMemoryManager behavior on FASTLED_RMT_STATIC_ALLOCATION—the main PR makes free()/freeDMA() no-ops under that macro, while the linked PR introduces the macro and alters calculateMemoryBlocks().

Poem

🐰 When memory stands still and won't dance,
No need to untie its advance;
Static lifts high, dynamic rests—
Allocation simplified, truly the best! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 directly and specifically describes the main change: making free()/freeDMA() no-ops under FASTLED_RMT_STATIC_ALLOCATION for performance optimization, and clearly references the associated meta-issue item.
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.6-static-alloc-fixed-ledger

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 merged commit ef6e378 into master Jun 6, 2026
7 checks passed
@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.6-static-alloc-fixed-ledger branch August 21, 2026 19:15
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