Skip to content

perf(rmt5): single-channel fast path in beginTransmission (#5382) - #5419

Merged
zackees merged 1 commit into
masterfrom
perf/5382-rmt5-single-channel
Nov 22, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/5382-rmt5-single-channel

Conversation

@zackees

@zackees zackees commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #5382; part of #5375 / #5356.

A frame containing one RMT5 strip now acquires and submits its hardware channel directly, avoiding temporary shared_ptr copies, sorting, and pending-queue insertion/removal. Multi-strip frames retain their existing ordering and queue scheduling. Both paths share acquisition, pooled-buffer submission, and failure cleanup. Pending entries retain their ChannelData owner and read its immutable pin/timing rather than duplicating that metadata.

Initial measurements against master da963db, using fbuild 2.5.53+git.e21167a56700:

Measurement Before After
ESP32-C6 legacy RMT instructions/show 10,529 9,868
ESP32-C6 mean show() 112.5 µs 154.6 µs
ESP32-S3 Blink image_flash 318,787 B 318,695 B

The initial instruction saving is 661/show (6.3%). The initial +42.1 µs wall-time result triggered a merge hold despite passing the 280 µs gate. Attributed S3 RAM remains 22,499 B. The flash ratchet falls from 318,783 B to 318,695 B; budget ceilings remain unchanged.

The hold is now resolved by the alternating investigation below. No additional RMT driver change was needed.

Alternating C6 investigation, 2026-11-22: flash BEFORE da963db, AFTER 5b832b6, BEFORE, AFTER, applying the identical temporary diagnostic probe from stash diag5382 to both revisions. Each image passed:

bash autoresearch esp32c6 --legacy --rmt --upload-port /dev/ttyACM1 --skip-lint --timeout 5m

After each image's normal gate, call timingDriftTest through the fbuild-backed RPC bench with {"pin":0,"numLeds":35,"iterations":2,"countInstructions":true}, then the same arguments with countInstructions:false. Every row is 554 shows, 35 LEDs, legacy RMT, 160 MHz, serial 8C:BF:EA:CF:87:B4. Instruction and real-cycle counts require separate runs: InstructionCounter temporarily repurposes IDF's cycle counter. Real cycles below are read with instruction counting disabled, not calculated from wall time. Timing includes the same micros probes in both modes; real-cycle intervals also include their small timestamp overhead. Post-show polling and histogram updates occur outside the measured interval.

Alternating image Counter mode Instructions/show Real cycles/show Mean µs p50 µs Max µs DRAINING / READY after show
BEFORE1 instr 10547.9 - 139.7 140 173 554 / 0
BEFORE1 cycle - 22160.6 137.4 137 149 554 / 0
AFTER1 instr 9870.1 - 155.5 156 167 554 / 0
AFTER1 cycle - 24253.7 149.6 149 165 554 / 0
BEFORE2 instr 10536.0 - 139.6 140 171 554 / 0
BEFORE2 cycle - 22152.2 137.3 137 149 554 / 0
AFTER2 instr 9869.1 - 155.4 155 168 554 / 0
AFTER2 cycle - 24259.1 149.7 149 167 554 / 0

Diagnosis: the counter-off mean difference is +12.3 µs in the first pair and +12.4 µs in the second pair, within the accepted ±10–20 µs code-layout band. Counter-on differences are approximately +15.8 µs in both pairs. All 4,432 observed shows return DRAINING, never READY: the direct path does not wait for the transmission to complete. Source review confirms the hardware acquire, buffer copy, encoder reset, cache sync, and transmit operations are extracted unchanged from the pending path; no wait was added, and the success branch returns immediately after submission. Real cycles track elapsed time rather than exposing a separate serialization effect. The mean stays far below the roughly 1,050 µs LED wire time.

The original +42 µs is not reproduced under identical instrumentation and alternation. It is benchmark/code-layout sensitivity, not evidence of a new transmit wait. An earlier identical histogram-only probe on both revisions even reversed the sign (BEFORE 172.6 µs, AFTER 163.6 µs, twice). These experiments establish the accepted within-noise result; they do not identify a specific original instruction address or cache stall. Instructions remain consistently lower (about 10,542 to 9,870/show in this alternation). Merge hold released on this evidence.

Diagnostic changes are excluded from this PR. Real-cycle and post-show state controls landed separately in #5421, after removing the temporary 4 KiB histogram and isolating platform access.

Validation:

  • RED before implementation in quick and debug: the padding callback observed 4 ChannelData owners instead of the 2 caller/enqueued owners. The test checks initial hardware allocation, idle-channel reuse, exact transmitted bytes, DRAINING, completion, and READY.
  • Strengthened the existing two-strip/one-hardware-channel test to verify queued transmission pins and lengths.
  • GREEN: bash test channel_driver_rmt --debug (ASAN/UBSAN).
  • bash test --cpp.
  • bash lint.
  • uv run pytest -q ci/tests -n auto.
  • C6 AutoResearch and S3 bloat passed; independent code review approved.
  • This investigation: four alternating C6 AutoResearch passes plus eight raw RPC counter/state runs; independent source review found no added wait.

Flash command: bash bloat esp32s3 --build.

Submit a lone strip directly and share hardware submission with queued strips. Verify ownership and queue behavior, and lower the measured S3 flash ratchet.

Refs #5375, #5356.
@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 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 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 driver now uses shared transmission setup for direct and queued submissions. When one channel is submitted with no pending work, beginTransmission attempts it directly. Tests cover repeated single-channel frames and channel-limit transmission details.

Changes: RMT5 transmission

Layer / File(s) Summary
Shared transmission setup and queued processing
src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp, tests/unit/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp
Pending entries now store channel data pointers. The shared transmission function handles acquisition, buffer preparation, channel setup, DMA cache synchronization, and submission. Queued processing retains items for retry and tests verify transmission pins and buffer sizes.
Single-channel direct submission
src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp, tests/unit/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp, tests/data/esp32s3_bloat_baseline.txt
A single channel is attempted directly when no work is pending. Tests check two successive frames, shared-owner counts, transmitted bytes, and driver state. The ESP32-S3 baseline records a 92 B reduction and a 318,695 B image.

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

Change: Refactor

Possibly related issues

  • Issue 5356: The single-channel direct path removes pending-queue bookkeeping for that case, addressing part of the issue’s stated goal of reducing per-frame channel bookkeeping.
Merge Risk: Minimal · up to 5b832

This change adds a direct submission path for single-strip RMT5 frames and keeps queued behavior for multi-strip frames. No actionable merge-blocking risk was found. The author reports the relevant tests and the flash ratchet passing.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "perf(rmt5): single-channel fast path in beginTransmission (#5382)" names the primary change. The summary and objectives describe a direct submission path for single-strip RMT5 frames in beg…
Linked Issues check Passed [#5382] The objective is a single-channel fast path in ChannelEngineRMTImpl::beginTransmission() that acquires and submits one hardware channel directly, without the shared_ptr copy, sort, and pending…
Out of Scope Changes check Passed The changed files are the RMT5 channel driver implementation, its unit test file, and the ESP32-S3 bloat baseline in tests/data/esp32s3_bloat_baseline.txt. The driver and test changes implement the #5…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "perf(rmt5): single-channel fast path in beginTransmission (#5382)" names the primary change. The summary and objectives describe a direct submission path for single-strip RMT5 frames in beginTransmission, which the title covers. The title uses a conventional prefix and an issue reference, and it is specific enough for a teammate scanning history. The title does not mention the shared transmitTransmitChannel refactor or the test additions, which is acceptable because the title need not cover every detail.

Full details: Linked Issues check

Explanation

[#5382] The objective is a single-channel fast path in ChannelEngineRMTImpl::beginTransmission() that acquires and submits one hardware channel directly, without the shared_ptr copy, sort, and pending-queue round trip, while multi-strip frames keep the queued path. The PR summary and description state that this path exists. The supporting code is in src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp, which introduces transmitChannel() as a shared acquisition and submission helper. The new test in tests/unit/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp checks that the padding callback sees 2 caller and enqueued owners instead of 4, and checks hardware allocation, idle-channel reuse, transmitted bytes, DRAINING, completion, and READY. This covers the required host test for a single-channel frame. The strengthened two-strip test checks queued pins and lengths, which covers the constraint that multi-strip behavior is preserved. Limitation: the beginTransmission() body was not read directly. The repository read was truncated at 16000 bytes and the focused diff reads failed, so the fast-path logic rests on the PR summary and the test's owner-count assertion. The ESP32-C6 instruction counts, S3 flash size, and latency gate results are reported by the author and were not reproduced. These are non-coding gates and were not assessed as coding requirements.

Full details: Out of Scope Changes check

Explanation

The changed files are the RMT5 channel driver implementation, its unit test file, and the ESP32-S3 bloat baseline in tests/data/esp32s3_bloat_baseline.txt. The driver and test changes implement the #5382 fast path and its test. The baseline change lowers the flash ratchet to match the reported image size and documents the change. It does not alter budget ceilings, according to the PR description and summary. The PR description states that the pending-entry change, which stores only ChannelDataPtr and reads pin and timing from ChannelData, supports the shared submission path. No unrelated behavior change was identified in the available evidence. Limitation: the full diff of the driver file could not be read, so this verdict rests on the PR summary.

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 da963db and 5b832b6.

Files selected for processing: 3

  • src/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp.hpp
  • tests/data/esp32s3_bloat_baseline.txt
  • tests/unit/platforms/esp/32/drivers/rmt/rmt_5/channel_driver_rmt.cpp

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

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 22, 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 22, 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 322,078 ($\color{green}\downarrow$ 236) 13,794 (Same)
esp32c6 351,348 (Same) 17,885 (Same)
esp32dev 286,331 ($\color{green}\downarrow$ 64) 18,747 (Same)
esp32s3 318,695 ($\color{green}\downarrow$ 92) 22,499 (Same)
esp8266 264,635 (Same) 6,808 (Same)
nrf52840_dk 66,944 (Same) 19,468 (Same)
rp2040 102,020 (Same) 8,624 (Same)
stm32f103c8 21,732 (Same) 1,789 (Same)
teensy41 46,080 (Same) 21,738 (Same)
uno 3,600 (Same) 134 (Same)

@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 22, 2026
@zackees
zackees added this pull request to the merge queue Nov 22, 2026
@github-actions github-actions Bot removed the sanitized Title, body and conversation screened; review text requires separate screening. label Nov 22, 2026
Merged via the queue into master with commit 478d853 Nov 22, 2026
428 of 451 checks passed
@zackees
zackees deleted the perf/5382-rmt5-single-channel branch November 22, 2026 09:21
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Nov 22, 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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

perf(rmt5): single-channel fast path in beginTransmission (no copy/sort/pending queue) (#5375)

1 participant