Skip to content

fix(parlio): size DMA buffers from per-lane input bytes - #2519

Merged
zackees merged 1 commit into
masterfrom
perf/parlio-trace-2518
May 29, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/parlio-trace-2518

Conversation

@zackees

@zackees zackees commented May 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes the PARLIO DMA sizing bug found while narrowing #2518. The ring-buffer calculator was treating maxLedsPerChannel * 3 * dataWidth as the input byte count, but the engine streams byte positions per lane and outputBytesPerInputByte() already includes dataWidth during waveform transposition.

For the 12 x 256 WS2812B ESP32-P4 case, that oversized the per-buffer capacity to about 590 KB for a 36,996-byte encoded frame. The hot path then zeroed/populated far more memory than needed before each transmission.

Changes

  • Size PARLIO DMA buffers from per-lane input bytes.
  • Align buffer chunking on a per-lane RGB byte boundary (3) instead of 3 * dataWidth.
  • Zero only explicit padding regions instead of clearing the whole DMA buffer capacity.
  • Update PARLIO calculator tests, including the 256 LED / 16-lane Wave3 case.

Measurements

ESP32-P4 EV, COM25, 12 lanes x 256 WS2812B, pins 2,27,3,26,4,23,5,22,49,21,50,20, FastLED.setMaxRefreshRate(0, false), FastLED.setExclusiveDriver(fl::Bus::PARLIO).

Current master baseline from #2518:

show_min_us=24938
show_avg_us=24993
show_max_us=25069

Trace before fix:

show_total_us=24987
show_on_begin_us=8879
show_internal_us=3574
show_on_end_frame_us=12429
manager_on_end_show_us=12316
parlio_begin_total_us=10912
parlio_populate_us=10690
parlio_ring_capacity=590144
parlio_first_buffer_bytes=36996
parlio_buffers_populated=1

Final production-code measurement after fix:

show_min_us=16963
show_avg_us=16998
show_max_us=17022
samples=40

The remaining time is dominated by the current single-buffer design: the next show() waits for the previous PARLIO transfer to finish before channel data can be rewritten, then it encodes current frame channel data and builds the next DMA waveform.

Tests

Fixes #2518.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected DMA ring buffer capacity calculations for ESP32 parallel I/O driver.
    • Improved buffer padding and alignment handling during LED data transmission.
    • Enhanced support for larger LED configurations.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown

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: 7bccfa35-1ba9-4e2d-a1ae-05850bddf046

📥 Commits

Reviewing files that changed from the base of the PR and between dc586bf and 4061bcb.

📒 Files selected for processing (3)
  • src/platforms/esp/32/drivers/parlio/parlio_buffer_calc.h
  • src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
  • tests/platforms/esp/32/drivers/parlio/parlio_driver.cpp

📝 Walkthrough

Walkthrough

Ring buffer capacity calculation refactored to account for mDataWidth expansion in downstream functions rather than upfront; buffer initialization changed from pre-zeroing entire DMA slots to conditional zeroing of only required padding regions during waveform population.

Changes

PARLIO buffer accounting and padding refactor

Layer / File(s) Summary
Ring buffer capacity per-lane accounting
src/platforms/esp/32/drivers/parlio/parlio_buffer_calc.h
calculateRingBufferCapacity documentation and totalInputBytes/inputBytesPerBuffer calculations updated from ... * mDataWidth to per-lane byte counts, with mDataWidth expansion deferred to dmaBufferSize() and outputBytesPerInputByte().
DMA buffer alignment and conditional padding zeroing
src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
LED-boundary alignment constant changed from 3 * dataWidth to fixed 3-byte value; workerIsrCallback() and populateNextDMABuffer() no longer pre-zero entire output buffer slots; populateDmaBuffer() front-padding zeroing is now conditional, and back/reset-padding explicitly zeroed only when present instead of assuming pre-zeroed memory.
Capacity and initialization test updates
tests/platforms/esp/32/drivers/parlio/parlio_driver.cpp
Expected calculateRingBufferCapacity result updated to 1120 for the 10-LED 4-lane case; new Wave3 16-lane test case with 280us reset added, asserting capacity of 37124 with PSRAM limit parameter.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Per-lane bytes dance through the ring,
No upfront zeroes—let padding sing!
DMA buffers trim their stride,
Conditional clears, none wasted, tried.
Ring slots lean and smart, aligned just right! 🎯

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(parlio): size DMA buffers from per-lane input bytes' directly describes the main change—fixing how PARLIO DMA buffers are sized by using per-lane input bytes instead of multiplying by dataWidth.
Linked Issues check ✅ Passed The PR directly addresses #2518's root cause by fixing oversized DMA buffer capacity calculations and reducing excessive memory zeroing, achieving the stated performance improvement from ~24.99ms to ~16.99ms on the 12×256 ESP32-P4 case.
Out of Scope Changes check ✅ Passed All changes are scoped to PARLIO DMA sizing logic: ring-buffer calculation, per-lane byte counting, padding behavior, and related tests. No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 perf/parlio-trace-2518

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

None yet

Development

Successfully merging this pull request may close these issues.

perf(parlio): umbrella for ESP32-P4 PARLIO output and show timing work

1 participant