Skip to content

perf(rmt5): split allocateTx fail-path into cold helper (#2773 item 2.5) - #2840

Merged
zackees merged 2 commits into
masterfrom
feat/2773-2.5-rmt-memmgr-cold-split
Jun 6, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/2773-2.5-rmt-memmgr-cold-split

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Same cold-helper pattern that worked for #2773 items 2.1 (PR #2830) and 2.2 (PR #2838). Applied here to RmtMemoryManager::allocateTx.

Hot path was bloated by the single-buffer fallback retry + 4 `FL_WARN` diagnostic lines + 3 conditional suggestion blocks — all of which reach for `fl::sstream operator<<` chains. The hot path (initial `tryAllocateWords` succeeds — the common Blink boot case where there's plenty of TX memory) now ends at a single conditional helper call:

```cpp
if (!tryAllocateWords(words_needed, true)) {
return handleAllocateTxFailure(channel_id, mem_blocks,
words_needed, networkActive);
}
```

Cold path is behaviorally unchanged.

This captures the easy share of #2773 item 2.5's ~3-4 KB target. The full template-trait refactor (skip the runtime planner entirely when `addLeds<>` is called exactly once with a known length) is still TODO but is a multi-day effort with template-instantiation risk.

Test plan

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved internal TX memory-allocation flow to separate common fallback and diagnostic logic from the hot allocation path.
    • Consolidated failure handling so allocation errors yield clearer, context-aware warnings and actionable suggestions, and recovered allocations are recorded consistently.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Worried about impact? Review this PR in Change Stack to explore blast radius before you approve or request 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: f5c69837-ed13-4459-9716-2422bf453618

📥 Commits

Reviewing files that changed from the base of the PR and between df55878 and 60e4c67.

📒 Files selected for processing (1)
  • src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp

📝 Walkthrough

Walkthrough

allocateTx now delegates insufficient TX allocation handling to a new cold helper, handleAllocateTxFailure, which performs progressive 1× buffering fallback, updates the ledger on recovered allocations, and emits consolidated diagnostics on final failure.

Changes

TX Allocation Failure Handler Refactoring

Layer / File(s) Summary
Failure handler declaration
src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.h
New private method handleAllocateTxFailure declared to accept TX channel ID, memory block/count, requested words, and network-active flag, returning either recovered word count or RmtMemoryError.
Failure handler implementation and allocateTx refactoring
src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp
allocateTx routes allocation failures to the new cold helper instead of inline logic; the helper attempts 1× buffering fallback, updates the ledger on success, and logs detailed memory breakdowns and context-specific failure suggestions before returning an error.

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • FastLED/FastLED#2826: Related refactor extracting RMT5 cold-path allocation/recovery helpers with similar goals and patterns.

🐰
A tiny helper digs and tries again,
When buffers shrink and hopes grow thin.
Cold paths tidy, logs sing clear,
Ledger notes what once was dear.
Allocation hops — we cheer, my dear!

🚥 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 accurately describes the main change: extracting the allocateTx failure path into a cold helper for performance optimization.
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-2.5-rmt-memmgr-cold-split

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp`:
- Line 432: Replace emoji prefixes in the diagnostic log strings with text-based
prefixes: locate the FL_LOG_RMT calls in rmt_memory_manager.cpp.hpp (e.g., the
line that logs "✓ Fallback successful: allocated ..." and the line that logs "✗
..." around the fallback logic) and change the emoji to readable text prefixes
such as "[OK]" for success and "[FAIL]" or "[ERROR]" for failure, preserving the
rest of the message and formatting.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8175c1e0-d6f3-47ff-b4d2-671dfd9abba7

📥 Commits

Reviewing files that changed from the base of the PR and between ebd8791 and 846900f.

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

…NLINE cold helper (#2773 item 2.5 — easy share)

Same cold-helper pattern that worked for #2773 items 2.1 (PR #2830) and
2.2 (PR #2838).

Hot path of allocateTx (initial tryAllocateWords succeeds — the common
Blink boot case where there's plenty of TX memory) was bloated by the
single-buffer fallback retry + 4 FL_WARN diagnostic lines + 3 conditional
suggestion blocks, all of which reach for fl::sstream operator<< chains.

Extract them into handleAllocateTxFailure(), an FL_NO_INLINE member
helper. Hot path now ends at:

    if (!tryAllocateWords(words_needed, true)) {
        return handleAllocateTxFailure(channel_id, mem_blocks,
                                       words_needed, networkActive);
    }

Cold path is behaviorally unchanged.

This captures the easy share of #2773 item 2.5's ~3-4 KB target. The
full template-trait refactor (skip the runtime planner entirely when
addLeds<> is called exactly once with a known length) is still TODO
but is a multi-day effort with template-instantiation risk.
@zackees
zackees force-pushed the feat/2773-2.5-rmt-memmgr-cold-split branch from 846900f to df55878 Compare June 6, 2026 00:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.h (1)

450-452: ⚡ Quick win

Add FL_NO_INLINE to the declaration to match the implementation.

The implementation in rmt_memory_manager.cpp.hpp (line 409) has FL_NO_INLINE before the return type, but the declaration here omits it. Since preventing inlining is central to the performance goal of this PR (#2773 item 2.5), the declaration should include the attribute for consistency and to document the performance-critical nature of this cold-path helper.

♻️ Proposed fix to add FL_NO_INLINE
     /// `@brief` Cold-path fallback + diagnostic for failed TX allocations.
     /// Extracted from allocateTx so the hot path (initial tryAllocateWords
     /// succeeds — the common Blink boot case) doesn't inline the single-buffer
     /// retry block, the FL_WARN diagnostic strings, or the suggestion
     /// messages. Returns the recovered allocation size on success, or a
     /// failure result on hard failure. See `#2773` item 2.5.
-    result<size_t, RmtMemoryError> handleAllocateTxFailure(
+    FL_NO_INLINE result<size_t, RmtMemoryError> handleAllocateTxFailure(
         u8 channel_id, size_t mem_blocks, size_t words_needed,
         bool networkActive) FL_NOEXCEPT;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.h` around lines 450
- 452, The declaration of the cold-path helper handleAllocateTxFailure(u8
channel_id, size_t mem_blocks, size_t words_needed, bool networkActive) omits
the FL_NO_INLINE attribute that the implementation uses; update the function
prototype for handleAllocateTxFailure in the header to include FL_NO_INLINE
before the return type so the declaration matches the implementation (and
documents/prevents inlining for this performance-critical helper).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.h`:
- Around line 450-452: The declaration of the cold-path helper
handleAllocateTxFailure(u8 channel_id, size_t mem_blocks, size_t words_needed,
bool networkActive) omits the FL_NO_INLINE attribute that the implementation
uses; update the function prototype for handleAllocateTxFailure in the header to
include FL_NO_INLINE before the return type so the declaration matches the
implementation (and documents/prevents inlining for this performance-critical
helper).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f69bfc85-e107-4f42-aad4-b2391e18b152

📥 Commits

Reviewing files that changed from the base of the PR and between 846900f and df55878.

📒 Files selected for processing (2)
  • 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
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/platforms/esp/32/drivers/rmt/rmt_5/rmt_memory_manager.cpp.hpp

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