Skip to content

perf(rmt5): keep a reused RMT channel enabled between frames (#5359) - #5360

Merged
zackees merged 1 commit into
masterfrom
perf/5359-rmt-keep-enabled
Nov 21, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/5359-rmt-keep-enabled

Conversation

@zackees

@zackees zackees commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Fixes #5359. Part of #5356.

Why

The RMT5 engine ran rmt_enable() before every transmission and rmt_disable() on completion. The next frame then reused the same channel on the same pin, so the pair was pure overhead. A cycle-counter profile on an ESP32-C6 (35 WS2812, forced-RMT legacy path) put it at 13 µs to enable plus 32 µs to disable and release, per frame.

What

  • A reused channel stays enabled (ChannelState::enabled).
  • Every RMT handle deletion goes through deleteHwChannel(). It disables the channel first because rmt_del_channel() rejects an enabled channel, and it refuses to delete if the disable fails.
  • reclaimPin() clears the flag because rebindTxPin() disables the channel for rmt_tx_switch_gpio().
  • With CONFIG_PM_ENABLE the channel is still disabled after each frame. Otherwise rmt_enable()'s PM lock would block light sleep for as long as a strip exists.
  • Also fixes a pre-existing double decrement of mDMAChannelsInUse in configureChannel() when callback registration fails.
  • The RMT mock now enforces IDF's state rules: no double enable, no delete while enabled, and a rebind leaves the channel disabled. It also counts enables.

Evidence

  • Host RED → GREEN:
    • Before the fix, RMT5 driver - reused channel stays enabled across frames fails: getEnableCount() is 4 after 4 frames, and the test expects 1.
    • The extended reused channel reclaims a rerouted pin fails if reclaimPin() does not clear the flag.
  • Device, ESP32-C6, bash autoresearch esp32c6 --legacy --rmt + ci.autoresearch.test_timing_drift, same session:
build show() min / mean / max
master 342 / 356.5 / 652 µs
this PR 310 / 333.1 / 627 µs

The AutoResearch run passed 4/4 tests.

  • ESP32-S3 image_flash: unchanged locally (320383 B, same as master), so the baseline is not touched.

Summary by CodeRabbit

  • Bug Fixes
    • Improved RMT channel reuse across repeated transmissions, avoiding unnecessary re-enabling when supported.
    • Fixed pin rebinding so cached channels can transmit successfully after their routing changes.
    • Ensured enabled channels are disabled before deletion, preventing cleanup failures.

ChannelEngineRMTImpl enabled the RMT channel before every transmission
and disabled it on completion, although the next frame reuses the same
channel on the same pin. On an ESP32-C6 (35 WS2812, forced-RMT legacy
path) the pair cost ~45 us per frame.

A reused channel now stays enabled. Every handle deletion goes through
deleteHwChannel(), which disables first because rmt_del_channel()
rejects an enabled channel and refuses to delete if the disable fails.
reclaimPin() clears the flag because rebindTxPin() disables the channel.
With CONFIG_PM_ENABLE the channel is still disabled after each frame so
rmt_enable()'s PM lock does not block light sleep.

Also fixes a pre-existing double decrement of mDMAChannelsInUse when
callback registration fails in configureChannel().

The RMT mock now enforces IDF's state rules (no double enable, no
delete while enabled, rebind leaves the channel disabled) and counts
enables.

ESP32-C6 show(), same session: master 342/356.5/652 us -> 310/333.1/627 us
(min/mean/max). ESP32-S3 image_flash unchanged (local 320383 B).
@zackees zackees added ci-platform:esp32c6 Select FastLED board CI cells ci-platform:esp32s3 Select FastLED board CI cells ci-test:bloat Select FastLED board CI cells labels Nov 21, 2026
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

No actionable comments were generated in the recent review.

Walkthrough

The RMT5 engine now tracks channel enablement and reuses enabled channels across frames. It disables channels before deletion, including during rebinding, reconfiguration, and cleanup. The mock and tests now check these channel state rules and repeated-frame behavior.

Changes: RMT5 channel reuse

Layer / File(s) Summary
Track channel state and reuse between frames
src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp
The engine tracks whether each channel is enabled and skips repeated enable operations for enabled channels. On completion, it disables a channel only when CONFIG_PM_ENABLE is defined.
Disable channels before rebinding or deletion
src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp, src/platforms/esp/32/drivers/rmt/rmt_5/rmt5_peripheral_esp.cpp.hpp
Channel cleanup uses deleteHwChannel to disable an enabled channel before deletion. Pin rebinding clears the engine’s enabled-state tracking.
Enforce and test channel lifecycle rules
src/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.h, src/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.cpp.hpp, tests/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp, tests/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.cpp
The mock rejects repeated enables and deletion while enabled, and counts successful enables. Tests cover repeated frames, pin rebinding, and disabling before deletion.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor · Severity of issue fixed: Medium

Possibly related issues

  • Issue 5356: The change keeps a reused RMT5 channel enabled between frames, addressing the per-frame channel enable and disable cost described in the issue. The issue also describes other per-frame costs that this change does not cover.
Merge Risk: Minimal · up to bd06f

This change keeps a reused RMT channel enabled between frames, which cuts per-frame show() overhead. It still disables the channel after each frame when power management is enabled. No concrete merge-blocking defect was established. One unlikely edge case, a failed disable during pin reconfiguration, behaves the same as before and has no demonstrated trigger.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: the RMT5 driver now keeps a reused channel enabled between frames instead of enabling and disabling it around every frame. The raw summary, objectives, and linked issu…
Linked Issues check Passed Directly linked issue #5359 has these coding requirements. (1) Keep a reused RMT channel enabled between frames. The change adds ChannelState::enabled and enables a channel only when it is not alrea…
Out of Scope Changes check Passed Changes map to #5359 except one. The mDMAChannelsInUse double-decrement fix in configureChannel() is a separate pre-existing bug. It is disclosed in the PR description. It sits in the same functio…
Full details: Title check

Explanation

The title names the main change: the RMT5 driver now keeps a reused channel enabled between frames instead of enabling and disabling it around every frame. The raw summary, objectives, and linked issue #5359 all describe this change. The title is specific, uses the conventional commit prefix, and has no vague terms. The title carries a PR number, (#5359), but the objectives reference PR #5360 for the same title, so the number does not match the linked PR. That mismatch is a metadata issue and does not affect the title's relevance to the changeset.

Full details: Linked Issues check

Explanation

Directly linked issue #5359 has these coding requirements. (1) Keep a reused RMT channel enabled between frames. The change adds ChannelState::enabled and enables a channel only when it is not already enabled. Without CONFIG_PM_ENABLE, the channel stays enabled after completion. (2) Disable a channel only before handle deletion, through one helper. deleteHwChannel() disables an enabled channel before rmt_del_channel(). Pin change, encoder failure, reconfiguration, and destructor paths use this helper, and the destructor no longer disables channels directly. (3) The RMT mock enforces IDF state rules and counts enables. enableChannel rejects a second enable, deleteChannel rejects enabled channels, rebindTxPin disables the channel, and getEnableCount() is added. (4) Automated tests cover the behavior. RMT5 driver - reused channel stays enabled across frames checks one enable over four frames. The rerouted-pin test checks that reclaimPin() clears the flag. The PR description adds the CONFIG_PM_ENABLE condition from the PR objectives, and the code path matches it per the change summary. The review used the change summary and PR description, not a line-level diff read, so line-level details are not independently verified.

Full details: Out of Scope Changes check

Explanation

Changes map to #5359 except one. The mDMAChannelsInUse double-decrement fix in configureChannel() is a separate pre-existing bug. It is disclosed in the PR description. It sits in the same function that the channel-state changes touch, so it is a closely related fix and not an unrelated change. The mock, test, and rmt5_peripheral_esp comment changes support the requested mock and state-rule behavior. The ESP32-C6 timing and ESP32-S3 image_flash results are evidence claims, not code changes, and they do not affect this assessment.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7d2064d and bd06fd9.

Files selected for processing: 6

  • src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp
  • src/platforms/esp/32/drivers/rmt/rmt_5/rmt5_peripheral_esp.cpp.hpp
  • src/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.cpp.hpp
  • src/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.h
  • tests/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp
  • tests/platforms/shared/mock/esp/32/drivers/rmt5_peripheral_mock.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@github-actions github-actions Bot added the sanitized Title, body and conversation screened; review text requires separate screening. label Nov 21, 2026
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 21, 2026
@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Memory usage (this PR vs. its merge base)

Change in examples/Blink per target. The left number is this PR's image flash / attributed RAM in bytes; the colored delta is the change from the merge base (red ↑ is larger, green ↓ is smaller, Same is unchanged).

Target FLASH [bytes] RAM [bytes]
attiny85 2,460 (Same) 136 (Same)
esp32c3 324,350 ($\color{red}\uparrow$ 22) 13,794 (Same)
esp32c6 354,708 (Same) 17,885 (Same)
esp32dev 287,803 ($\color{red}\uparrow$ 16) 18,747 (Same)
esp8266 264,671 (Same) 6,808 (Same)
nrf52840_dk 68,208 (Same) 19,468 (Same)
rp2040 103,212 (Same) 8,624 (Same)
stm32f103c8 22,928 (Same) 1,789 (Same)
teensy41 47,104 (Same) 21,738 (Same)
uno 3,600 (Same) 134 (Same)

No comparison (build missing on one side): esp32s3

@github-actions github-actions Bot added sanitized Title, body and conversation screened; review text requires separate screening. and removed sanitized Title, body and conversation screened; review text requires separate screening. labels Nov 21, 2026
@zackees
zackees added this pull request to the merge queue Nov 21, 2026
Merged via the queue into master with commit e6487d8 Nov 21, 2026
426 of 449 checks passed
@zackees
zackees deleted the perf/5359-rmt-keep-enabled branch November 21, 2026 20:47
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-platform:esp32c6 Select FastLED board CI cells ci-platform:esp32s3 Select FastLED board CI cells ci-test:bloat Select FastLED board CI cells sanitized Title, body and conversation screened; review text requires separate screening.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

perf(rmt5): stop enabling/disabling the RMT channel around every frame (#5356)

1 participant