Skip to content

refactor(rmt5): extract createChannel recovery sstream into noinline helpers (#2773 item 2.2 partial, −1820B) - #2826

Merged
zackees merged 1 commit into
masterfrom
memhunt/2773-iter-2-create-channel
Jun 5, 2026
Merged

zackees merged 1 commit into
masterfrom
memhunt/2773-iter-2-create-channel

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

fl::ChannelEngineRMTImpl::createChannel was 6351 B on the esp32dev Blink build — the largest FastLED-owned symbol in the binary per the #2773 batch-2 audit. Two of its cold paths each built a ~15-line fl::sstream with multi-integer interpolation (recovery success + allocation failure messages); every operator<< instantiation was being textually inlined into createChannel.

Move both into __attribute__((noinline)) member helpers. Pure code motion — same rodata, same FL_WARN/FL_ERROR severity, same on-the-wire output.

Size measurements (fbuild esp32dev release Blink)

Symbol Before After Delta
ChannelEngineRMTImpl::createChannel 6351 B 4531 B −1820 B (−28%)
ChannelEngineRMTImpl::emitRecoveryWarning (new) — 752 B +752 B
ChannelEngineRMTImpl::emitAllocationFailureError (new) — 798 B +798 B
firmware.bin total 791,263 B 791,035 B −228 B

The full multi-line texts are preserved (no diagnostic loss); the win is operator<< code no longer duplicated through createChannel's prologue/epilogue. The two helpers are cold-path, so --gc-sections keeps them tucked away from the hot allocation/encoder-creation block.

This is the first surgical pass at #2773 item 2.2. The full static/dynamic split (using a static-init thread-local so --gc-sections can drop the dynamic hot-plug body entirely) remains pending and tracks separately.

Test plan

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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Optimized internal error message handling in the ESP32 RMT driver module to improve code organization and maintainability.

…helpers (#2773 item 2.2 partial, −1820B on ESP32)

`fl::ChannelEngineRMTImpl::createChannel` was 6351 B on the esp32dev
Blink build — the largest FastLED-owned symbol in the binary (see #2773
batch-2 audit). Two of the cold paths inside createChannel each built a
~15-line `fl::sstream` with multi-integer interpolation: the recovery
warning (when progressive memory reduction succeeds) and the allocation
failure error (when even minimum-block retry fails). Every `operator<<`
instantiation in both was being textually inlined into createChannel,
multiplying the operator-chain code on a path that is taken only when
the RMT peripheral is contended at boot.

Move both into `__attribute__((noinline))` member helpers:
- `emitRecoveryWarning(original_symbols, reduced_symbols, external_words)`
- `emitAllocationFailureError(retry_count, original_symbols, min_symbols, pin)`

This is pure code motion — the rodata strings, the integer arguments
the user sees, the FL_WARN / FL_ERROR severity, and the on-the-wire
behaviour are all preserved.

## Size measurements (fbuild esp32dev release Blink)

Before:
```
000018cf W fl::ChannelEngineRMTImpl::createChannel(...)   6351 B
```

After:
```
000011b3 W fl::ChannelEngineRMTImpl::createChannel(...)   4531 B   (-1820 B, -28%)
000002f0 W fl::ChannelEngineRMTImpl::emitRecoveryWarning(...)     752 B   (new)
0000031e W fl::ChannelEngineRMTImpl::emitAllocationFailureError(...) 798 B (new)
```

Net firmware.bin: 791263 → 791035 B (-228 B). The textual size of the
sstream chains is preserved (we didn't drop any output) but the
operator<< code is no longer duplicated through the createChannel
prologue/epilogue. The two helpers are cold-path so `--gc-sections`
keeps them tucked away from the hot allocation/encoder-creation block.

This is the first of several extractions toward #2773 item 2.2 (split
createChannel static vs. dynamic). The full static/dynamic split (with
a static-init thread-local that lets `--gc-sections` drop the dynamic
hot-plug body entirely) is still pending and tracked separately.

Refs #2773.

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

coderabbitai Bot commented Jun 5, 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

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: 67a58f08-7766-4b06-bed2-aeff62d4e3dd

📥 Commits

Reviewing files that changed from the base of the PR and between c89379e and 368ae30.

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

📝 Walkthrough

Walkthrough

Two noinline private helper methods (emitRecoveryWarning and emitAllocationFailureError) are added to ChannelEngineRMTImpl to centralize cold-path diagnostic message construction. Two call sites within createChannel() are refactored to invoke these helpers instead of building messages inline, preserving all existing gating and control flow.

Changes

RMT5 Diagnostic Logging Refactor

Layer / File(s) Summary
Extract diagnostic message helpers
src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp
Two noinline private helper methods (emitRecoveryWarning and emitAllocationFailureError) are introduced to construct and emit allocation recovery and failure diagnostic messages. The recovery warning and allocation failure error paths in createChannel() are updated to call these helpers instead of building messages inline.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit refactors with care,
Cold paths extracted with flair,
Two helpers take flight,
Code bloat shrinks from sight,
Diagnostics now cleaner than air! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 clearly and specifically summarizes the main refactoring change: extracting recovery sstream construction into noinline helpers in the RMT5 driver, with concrete context about the issue number and size impact.
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-2-create-channel

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