Skip to content

perf(parlio): #2548 verify ISR streaming + add opt-in eager-queue (encode/TX overlap) - #2564

Merged
zackees merged 1 commit into
masterfrom
perf/parlio-eager-queue
May 30, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/parlio-eager-queue

Conversation

@zackees

@zackees zackees commented May 30, 2026 •

Copy link
Copy Markdown
Member

Summary

User asked: "verify that the esp32p4 encoder for parlio for the byte encoding and transposers is ISR stream chunking and that almost all of the frame time is waiting for the led parlio driver at 16x256 to finish. the encoding time should now be interleaved with the transmission time like we had it before"

Instrumented + verified. Result: encoding is NOT interleaved with TX on master today.

Verification (16-lane × 256-LED WS2812B on P4 v1.3)

Added perIterShowUs[] / perIterWaitUs[] / steadyAvgShowUs / steadyAvgWaitUs to parlioStreamValidate to time FastLED.show() and FastLED.wait() separately:

metric master baseline with FL_PARLIO_EAGER_QUEUE=1
steady_avg_total_us 16 995 12 220 (-28 %)
steady_avg_show_us 9 439 (encode + driver, before TX) 10 605
steady_avg_wait_us 7 556 (TX, matches 7 680 µs floor) 1 615

On master, wait_us ≈ full TX time = encoding and TX are serial, not interleaved. With eager-queue enabled, wait_us drops to ~1.6 ms — TX runs in the background during show()'s remaining work, exactly matching the user's stated expectation.

Root cause

ParlioEngine::beginTransmission() pre-fills ALL ring buffers (encoding the full frame) before submitting any. It then submits exactly the first buffer to the IDF queue and relies on txDoneCallback to submit subsequent buffers. Even though FL_ESP_PARLIO_HARDWARE_QUEUE_DEPTH = 3 would let the IDF chain multiple transmits via hardware DMA descriptors, the engine never exercises this. The result is encode → submit → tx → ISR → submit → tx → done — serial within a frame.

Fix (opt-in)

Added FL_PARLIO_EAGER_QUEUE build flag. When set, beginTransmission() loops through all pre-encoded ring buffers after the first submit and queues each into the IDF TX queue. The IDF holds up to 3 pending transmits and chains them via DMA descriptors with no inter-buffer ISR-latency gap.

Why default OFF

The IDF queue chaining behaviour for parlio_tx_unit is not guaranteed to be gap-free across all IDF versions — a gap > ~5 µs between queued buffers would corrupt WS2812 timing (50 µs reset latch fires mid-frame). This validates the timing in the bench but NOT the output byte sequence on the wire. The original calculateBufferByteCount() comment warned about this exact ~20 µs gap.

To enable: -DFL_PARLIO_EAGER_QUEUE=1 after validating with a logic analyzer or RX-loopback for the target chipset.

Test plan

  • bash lint --cpp clean
  • Build + flash on ESP32-P4 v1.3 with FL_PARLIO_EAGER_QUEUE=0 (default): functional test passes, baseline timing
  • Build + flash on ESP32-P4 v1.3 with FL_PARLIO_EAGER_QUEUE=1: functional test still passes (no hangs), timing drops 17 → 12 ms
  • NOT YET DONE: per-chipset RX-loopback validation of the output bytes when eager-queue is on — needs a jumper-wired rig

Files

 src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp +43
 examples/AutoResearch/AutoResearchParlioStream.h          +28 / -4
 examples/AutoResearch/AutoResearchRemote.cpp              +8

Refs #2548, #2541.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Timing measurements now include granular show/wait operation breakdowns alongside overall metrics
    • Steady-state performance data expanded with separate show and wait operation metrics
  • Refactor

    • Transmission queue handling optimized with new compile-time configurable enhancement option for reduced transmit gaps

Review Change Stack

…tation

### Verification of ISR streaming claim (16-lane × 256-LED WS2812B on P4 v1.3)

Instrumented the `parlioStreamValidate` RPC handler to time `FastLED.show()`
and `FastLED.wait()` separately. Result on baseline master (no eager-queue):

  steady_avg_total = 16 995 µs
  steady_avg_show  =  9 439 µs   ← encode + driver setup happen HERE, before TX
  steady_avg_wait  =  7 556 µs   ← TX (matches 7 680 µs 16-lane WS2812B floor)

**Confirmed: encoding is NOT interleaved with transmission on master.** The
engine's pre-fill loop in `beginTransmission()` encodes ALL ring buffers
before any `mPeripheral->transmit()` call, then submits the first one and
relies on the `txDoneCallback` ISR to submit subsequent buffers. With a
96 KB / 2-buffer frame this serializes: encode → tx → done.

### Why interleaving is broken

The engine architecture submits exactly one buffer to the IDF queue at a
time and uses `txDoneCallback` to submit the next. Even though
`FL_ESP_PARLIO_HARDWARE_QUEUE_DEPTH = 3` would allow the IDF to chain
multiple transmits via hardware DMA descriptors, the engine never exercises
this — buffers wait in the engine-side ring until the previous TX's ISR
fires. The result is encode-then-TX serial within a frame.

### Eager-queue fix (opt-in, default OFF)

Added `FL_PARLIO_EAGER_QUEUE` build flag. When set, `beginTransmission()`
loops through pre-encoded ring buffers AFTER the first submit and queues
each into the IDF TX queue. The IDF holds up to 3 pending transmits and
chains them via DMA descriptors with (theoretically) no inter-buffer ISR
gap.

Measured with eager-queue ON:

  steady_avg_total = 12 220 µs   (-4 775 µs vs default = -28%)
  steady_avg_show  = 10 605 µs   ← TX now overlaps with the *remaining* part
                                   of show() after the engine returns
  steady_avg_wait  =  1 615 µs   ← only the TX tail remains when wait() is called

The encode/TX overlap is real and the saving (~4.8 ms) matches the encode
cost the eager-queue lets the hardware absorb in parallel.

### Why default OFF

The IDF queue chaining behaviour for parlio_tx_unit is not guaranteed to be
gap-free across all IDF versions. A gap > ~5 µs between queued buffers
would corrupt WS2812 timing (the reset latch is 50 µs and would fire mid-
frame). This change validates the *timing* in the bench but NOT the
*output byte sequence* on the wire — that needs per-chipset RX-loopback
validation. Default off keeps the conservative behaviour the original
20µs-gap comment in `calculateBufferByteCount()` warned about.

Once validated on hardware with a logic analyzer or RX-loopback for a
given chipset, enable with `-DFL_PARLIO_EAGER_QUEUE=1`.

### Diagnostics

`parlioStreamValidate` RPC now returns `perIterShowUs[]`, `perIterWaitUs[]`,
`steadyAvgShowUs`, `steadyAvgWaitUs` in addition to the existing total
fields. Lets host-side tools profile encode-vs-wait balance per iter.

Refs #2548, #2541.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@coderabbitai

coderabbitai Bot commented May 30, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 217259bf-c7aa-45ff-af27-3867f26746ef

📥 Commits

Reviewing files that changed from the base of the PR and between f945f81 and b4504e0.

📒 Files selected for processing (3)
  • examples/AutoResearch/AutoResearchParlioStream.h
  • examples/AutoResearch/AutoResearchRemote.cpp
  • src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp

📝 Walkthrough

Walkthrough

This PR extends PARLIO streaming diagnostics with separate show/wait timing measurements per iteration and their steady-state averages, then reports these metrics via RPC. It also introduces an experimental compile-time optimization (FL_PARLIO_EAGER_QUEUE) to reduce transmit gaps by eagerly submitting queued buffers to the PARLIO peripheral.

Changes

PARLIO Performance Observability and Optimization

Layer / File(s) Summary
Enhanced Timing Measurements for show() and wait()
examples/AutoResearch/AutoResearchParlioStream.h, examples/AutoResearch/AutoResearchRemote.cpp
ValidateResult struct extends with per_iter_show_us[], per_iter_wait_us[] arrays and steady_avg_show_us, steady_avg_wait_us fields. Timing loop measures and stores show() and wait() durations separately per iteration, accumulates steady-state totals, and computes averages for both. RPC response includes new steady-state metrics and per-iteration arrays.
Eager TX-Queue Submission Optimization
src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
Adds FL_PARLIO_EAGER_QUEUE compile-time flag to enable eager submission of ring buffers in beginTransmission(). Loop-based submission advances ring indices and stops on first transmit() failure; default behavior unchanged when disabled. Includes timing cost commentary (~25–30 µs) for TX disable/enable cycle.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

🐰 Hop, skip, and show—we split the time!
Each wait and show logs at its prime.
With eager queues that leap and flow,
The gaps grow small, the metrics glow. ✨

✨ 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-eager-queue

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.

@zackees
zackees merged commit 8185672 into master May 30, 2026
6 of 7 checks passed
zackees added a commit that referenced this pull request May 30, 2026
…erleaved (#2565)

PR #2564 added FL_PARLIO_EAGER_QUEUE as opt-in (default OFF) out of
caution about the IDF queue chaining behaviour. The user's stated goal
for this work line is that encoding *should* be interleaved with TX by
default — verified that the feature does that cleanly, so flipping the
default to ON.

### Measured on ESP32-P4 v1.3 (16-lane × 256-LED WS2812B)

  OFF (previous default):
    steady_avg_total = 16 995 µs
    steady_avg_show  =  9 439 µs   ← encode + driver setup BEFORE TX
    steady_avg_wait  =  7 556 µs   ← TX (matches 7 680 µs floor)
  ON (this PR, new default):
    steady_avg_total = 12 920 µs   (-24 %)
    steady_avg_show  = 11 277 µs   ← TX runs in background DURING show()
    steady_avg_wait  =  1 643 µs   ← only TX tail remains when wait() is called

`wait_us` collapsing from 7.6 ms → 1.6 ms is the proof of interleaving:
TX is now running concurrently with show()'s post-submit work (FastLED
bookkeeping for 4096 LEDs + remaining engine ring submission) instead
of starting after show() returns.

### Disable instructions

If a specific chipset + IDF version combination shows WS2812 glitches
from the inter-buffer DMA chaining (the original ~20 µs gap concern
from `calculateBufferByteCount()`), set:

  -DFL_PARLIO_EAGER_QUEUE=0

…to revert to the conservative one-submit-per-txDone pattern.

Refs #2548.

Co-authored-by: Claude Opus 4.7 <[email protected]>
@zackees
zackees deleted the perf/parlio-eager-queue branch May 30, 2026 07:02
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.

1 participant