Skip to content

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

Closed

Description

@zackees

Context

This is the canonical umbrella for the ESP32-P4 PARLIO output and timing/performance work. Use this issue as the single cross-referenced tracker for the original slow FastLED.show() report, the complete missing-output detour, fbuild/autoresearch prerequisites, binding diagnostics, and the perf tracing/fix PRs used to narrow the remaining performance behavior.

The original user-visible timing symptom in #2493 was FastLED.show() blocking for 16 ms or more before the WS2812 data burst began. The later complete missing-output failure was split out and fixed by #2513 / #2515. This umbrella now tracks the end-to-end state and the remaining performance question.

Current confirmed state

Perf tracing and fix PRs

Measurements

Current-master baseline from the trace/fix pass:

show_min_us=24938
show_avg_us=24993
show_max_us=25069

Trace before the fix showed the time concentrated in PARLIO DMA preparation:

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 hardware timing from #2519:

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

What remains to decide

For 12 lanes x 256 WS2812B, the expected parallel data burst is roughly 7.7-9 ms depending on reset/latch accounting. After #2519, the measured show() time is roughly prior-frame PARLIO drain plus current-frame channel encoding and DMA waveform generation.

If this design is accepted as the current maximum for the single-buffer architecture, close this issue after #2519 lands and the final state is documented. If lower wall-clock show() time is required, the follow-up design work is broader than the DMA sizing fix: investigate double-buffered channel/DMA ownership so current-frame preparation can overlap the previous PARLIO transfer.

Acceptance criteria

Cross references

Activity

  1. zackees commented on May 28, 2026

    @zackees
    MemberAuthor

    Coordination note from clud for @zackees:

    This is the canonical umbrella issue for the current ESP32-P4 PARLIO work. It should be the single place to narrow the remaining performance issue, while the already split/fixed prerequisites stay cross-referenced instead of becoming competing tracking issues.

    Perf tracing PRs to use for narrowing the current ~24 ms steady-state FastLED.show() time:

    Related prerequisites and adjacent fixes:

    Next narrowing step: use #2508 if possible, or extract a minimal flash-dump trace path if AutoResearch remains blocked, and produce a current trace that separates onBeginFrame, showLedsInternal, onEndFrame, driver wait/poll, and PARLIO begin/submit/callback/poll time.

  2. zackees commented on May 28, 2026

    @zackees
    MemberAuthor

    clud for @zackees update:

    I traced the current ESP32-P4 PARLIO 12 x 256 case and opened the fix PR here:

    #2519

    Current-master baseline from the flash-backed timing sketch was still about 25 ms:

    show_min_us=24938
    show_avg_us=24993
    show_max_us=25069
    

    The trace narrowed the missing time to PARLIO DMA preparation, not the old 16 ms scheduler wait:

    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
    

    Root cause: the PARLIO ring-buffer calculator used maxLedsPerChannel * 3 * dataWidth as the input byte count even though the engine streams per-lane byte positions and outputBytesPerInputByte() already accounts for dataWidth. For 12 x 256 WS2812B this allocated a ~590 KB DMA buffer for a 36,996-byte encoded frame, and the hot path paid that cost each frame.

    PR #2519 fixes the per-lane sizing, fixes chunk alignment to 3 RGB bytes instead of 3 * dataWidth, and zeroes only explicit padding regions. Final production-code hardware timing after the fix:

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

    Verification run:

    Remaining behavior note: after this fix, the steady-state show() time is roughly prior-frame PARLIO drain (~8.9 ms in trace) plus current-frame channel encoding and DMA waveform generation. Getting materially below this would require a broader design change such as double-buffered channel/DMA ownership so current-frame preparation can overlap the previous PARLIO transfer.

  3. changed the title [-]perf(parlio): umbrella for ESP32-P4 show timing regression and trace narrowing[/-] [+]perf(parlio): umbrella for ESP32-P4 PARLIO output and show timing work[/+] on May 28, 2026
  4. zackees commented on May 28, 2026

    @zackees
    MemberAuthor

    clud for @zackees — ESP32-P4 PARLIO show() timing, measured live on the attached EV board (autoresearch RPC measureParlio, fixed #2519 firmware, debug build). Separates show() (encode) from wait() (DMA wire drain).

    It's encoder-bound, not wire-bound

    config total LEDs show_us (encode) wait_us (wire drain) nominal wire total fps
    1×256 256 1,411 6,443 7,680 ~127
    2×256 512 2,886 6,302 7,680 ~109
    4×256 1024 6,483 6,220 7,680 ~79
    8×256 2048 14,505 6,174 7,680 ~48
    16×256 4096 25,400 6,316 7,680 ~31
    16×128 2048 12,867 3,067 3,840 ~63
    16×64 1024 6,672 1,578 1,920 ~121
    • wait_us = WS2812 wire drain — depends only on LEDs/lane (lanes transmit in parallel): 256/lane → ~6.3ms regardless of lane count; 128 → 3.1ms; 64 → 1.6ms. This matches the protocol math (~120–150fps wire); a single 1×256 lane hits ~127fps total.
    • show_us = CPU waveform encode — scales with total LEDs across all lanes (~6µs/LED in debug): 256 → 1.4ms … 4096 → 25.4ms. At 16×256 the encode (25ms) dwarfs the wire (6.3ms) ⇒ ~31fps, encoder-bound.

    So the ~25ms show() for 16×256 is encode + wire serialized, not a wire limit. (Release -O2 encode is ~3× faster; the earlier "production" 17ms figure ≈ ~8ms encode + ~9ms drain.)

    Architectural factoids (confirmed in parlio_engine.cpp.hpp)

    1. DMA seam + late callback. PARLIO has a ~20µs inter-buffer DMA seam (documented in parlio_buffer_calc.h), and txDoneCallback is ISR-driven — it fires ~20µs late rather than instantly. Across buffer boundaries this corrupts WS2812 timing, which is exactly why fix(parlio): size DMA buffers from per-lane input bytes #2519 sizes the ring so the full frame fits in one buffer (one clean continuous DMA, no seam).

    2. No next-buffer pre-staging in the single-buffer path. In the full-frame single-buffer mode fix(parlio): size DMA buffers from per-lane input bytes #2519 selects for frames that fit (the common case), show() pre-populates/encodes the entire frame synchronously before starting DMA (the while (hasRingSpace() && populateNextDMABuffer()) loop at ~L1819), then transmits; the next frame is re-encoded from scratch on the next show(). There is no frame-level double-buffering — encode latency is fully exposed and serialized ahead of transmission. (The multi-ring-buffer streaming path does refill chunk buffers from the ISR, overlapping encode with transmit, but pays the ~20µs seam per boundary — so it trades correctness for overlap.)

    3. Design intent — hide encode behind transmission (not yet implemented). The encoder for frame N+1 should run after the pre-computed buffer for frame N is sent, so encode latency is hidden inside the transmission window. With frame-level ping-pong double-buffering (two full-frame buffers): submit buffer A (one clean DMA, no seam) → encode buffer B during A's ~6ms transmit → swap. Throughput → max(encode, wire) instead of encode + wire, and the ~20µs late-callback seam becomes irrelevant because the next buffer is already staged. For 16×256 in release this moves the ~17ms serialized figure toward the ~6–8ms wire floor (final gate = encode time, which then wants SIMD / multi-core).

    Coordination / next round

  5. zackees commented on May 28, 2026

    @zackees
    MemberAuthor

    Correction / sharpening (per @zackees): the intended design is that show() encodes only the first batch of ring buffers and the ISR encodes the remaining chunks during transmission (txDoneCallback → workerIsrCallback/populateNextDMABuffer), so encode latency hides inside the transmission gap. My previous comment understated this — the chunked-ISR-encode path is the design, not just a "multi-buffer alternative."

    The problem: that overlap is not engaging after #2519, and the data proves it.

    #2519 sizes the ring so the whole frame fits in one buffer (to avoid the ~20µs seam). Consequence: for frames that fit (the common case), show()'s pre-populate loop encodes the entire frame into that single buffer before DMA starts, and the ISR has nothing left to chunk-encode. Evidence:

    • The original trace in this issue: parlio_buffers_populated=1 (12×256) — one buffer holds the full frame.
    • My live sweep (16×256): show_us = 25.4ms scales with total LEDs (full-frame encode), while wait_us = 6.3ms is pure wire drain with no encode interleaved. If the ISR were chunk-encoding during TX, wait_us would carry encode time and show_us would be a fraction of the frame — it isn't.

    So today, on frames that fit in one buffer, encode is fully serialized ahead of transmission (show() = full encode, then wait() = full wire), not chunked/overlapped. This needs to be fixed so it matches the intended design.

    Fix direction (needs design decision): the two goals — "one continuous buffer (no seam)" and "chunked ISR encode overlapping TX" — currently conflict, because making the frame one buffer removes the chunk boundaries the ISR would encode at. Options:

    1. Frame-level ping-pong double-buffer (keeps fix(parlio): size DMA buffers from per-lane input bytes #2519's seam-free single DMA per frame): submit frame N's pre-computed buffer, encode frame N+1 into the second buffer during N's ~6ms transmit, swap. Encode of N+1 is hidden; the ~20µs late callback is irrelevant because the next buffer is already staged. Throughput → max(encode, wire).
    2. Restore intra-frame chunked streaming (show() encodes only the first 1–2 ring buffers, ISR encodes the rest), but then the ~20µs inter-buffer seam must be masked so it doesn't corrupt WS2812 timing (e.g., overlapping/aligned chunk boundaries, or pre-staging the next chunk so submit is instant on the late callback).

    Either way the requirement is the same: show() must not encode the full transmission sequence — the encoder must run during the transmission window. Right now it doesn't, for single-buffer frames.

    (Measurement firmware: branch feat/autoresearch-esp32p4-hwcdc; the measureParlio RPC reports show_us/wait_us and SRAM/PSRAM deltas. fbuild ESP32-P4 boot fixes per FastLED/fbuild#278 to be implemented in a sub-agent and pushed.)

  6. zackees commented on May 28, 2026

    @zackees
    MemberAuthor

    ESP32-P4 PARLIO show() performance — state report, memory/speed/seam analysis

    Measured live on the attached ESP32-P4-EV via the autoresearch RPC (measureParlio), fixed #2519 firmware. Decomposes show() into encode (CPU) and wait() into wire drain (DMA). Debug build — absolute µs are ~3× a release -O2 build; ratios and scaling laws hold.

    1. Perf decomposition (measured)

    config total LEDs show_us (encode) wait_us (wire) fps
    1×256 256 1,411 6,443 127
    4×256 1024 6,483 6,220 79
    8×256 2048 14,505 6,174 48
    16×256 4096 25,400 6,316 31
    16×128 2048 12,867 3,067 63
    16×64 1024 6,672 1,578 121
    • encode ∝ total LEDs (lanes × leds/lane), ~6µs/LED debug. Single-threaded across all lanes.
    • wire ∝ leds/lane only (lanes transmit in parallel): ~6.3ms for 256/lane regardless of lane count; halves with leds/lane.
    • Today show() and wait() are serialized → frame_time = encode + wire. Encode dominates ≥8 lanes.

    2. Memory model (analytic, corroborated)

    The engine allocates 3 DMA ring buffers, each sized to the full frame (parlio_engine.cpp.hpp L1089-1093). Per-frame bytes (Wave3):

    frame_bytes ≈ leds_per_lane × 3 × (3 × dataWidth) + padding
    dataWidth = next power-of-two ≥ lane_count  ∈ {1,2,4,8,16}
    

    e.g. 16×256 → 256×3×48 + 132 = 36,996 B/frame; ring total = 3 × 37,124 ≈ 109 KB.

    #2519 picks the single-buffer (seam-free) path when frame_bytes ≤ cap/3. P4 caps: 512 KB SRAM / 2 MB PSRAM (ring lives in PSRAM here). Max seam-free frame:

    lanes (dataWidth) bytes/LED max leds/lane, PSRAM (2MB/3) max leds/lane, SRAM (512KB/3)
    16 144 ~4,850 ~1,185
    8 72 ~9,700 ~2,370
    4 36 ~19,400 ~4,740
    1 9 ~77,000 ~19,000

    Seam-free memory grows with leds × dataWidth(lanes). Below these limits (the common case) a whole frame fits one buffer → one continuous DMA → no seam. Above them the frame must be chunked across buffers → seams.

    3. The 20µs transmission-gap (seam) tradeoff vs lane/LED count

    • The PARLIO inter-buffer DMA seam is ~20µs, and txDoneCallback fires ISR-late (not instant). Each chunk boundary inserts one seam.
    • Speed cost of chunking K pieces: (K-1)×20µs added to wire — small (e.g. 10 chunks ≈ +180µs ≈ +3% on a 6ms frame).
    • Correctness cost: a seam falling mid-LED corrupts all downstream LEDs (the reason fix(parlio): size DMA buffers from per-lane input bytes #2519 went single-buffer). LED-boundary-aligned chunking should keep the 20µs gap between whole LEDs (below the WS2812 ≥50µs reset), but this was not verifiable on this board — the RX loopback (GPIO5→6) is not wired, so seam-corruption could not be measured empirically; it remains a documented risk.
    • Net tradeoff: to stay seam-free you pay memory ∝ leds × dataWidth; once leds × dataWidth exceeds cap/3 (large installs, e.g. >~4,850 leds/lane at 16 lanes in PSRAM) you are forced to chunk and accept seams. So lane count and LED count push you toward the memory ceiling; crossing it forces the speed/correctness compromise of seams.

    4. Maximum perf for the current memory parameters

    The driver already allocates 3 full-frame buffers but transmits from only 1 in single-buffer mode — buffers 1 & 2 are paid for but idle. So throughput can be raised with no additional memory:

    Approach A — frame-level ping-pong double-buffer (uses 2 of the existing 3 buffers): submit frame N (one clean seam-free DMA) → encode frame N+1 into the other buffer during N's transmission → swap. Frame_time → max(encode, wire) instead of encode + wire. No intra-frame seam (per-frame DMA shape identical to the #2519-validated single-buffer case).

    Expected (16×256): debug 31ms→~25ms (encode-bound, +24%); release 14ms→8ms ≈ ~125fps (overlap roughly doubles fps when encode≈wire). Beyond this, the system is encode-bound — further gains need a faster encoder (SIMD / second core), which is orthogonal to memory.

    5. Recommendation / status

    • Implement Approach A (no memory increase; reuses allocated buffers; preserves validated per-frame DMA). Plan is file/line-scoped in beginTransmission (L1726-1900: replace the encode-everything loop L1819 with single-slot encode + deferred submit + slot swap), with the ISR refill path effectively inert (reduces the existing mRingCount race surface).
    • Validation gap: FPS/no-crash/no-error are verifiable here; WS2812 signal correctness needs the RX-loopback jumper (GPIO5→6) — required before merge.
    • Encode is the ceiling for high lane counts; recommend a follow-up to SIMD/parallelize the Wave3 transpose.

    Measurement firmware + measureParlio probe: branch feat/autoresearch-esp32p4-hwcdc. fbuild P4 boot fixes (FastLED/fbuild#278) to be implemented in a sub-agent and pushed. Autoresearch RPC docs drift filed as #2520.

  7. zackees commented on May 28, 2026

    @zackees
    MemberAuthor

    Implementation result — Approach A built + hardware-tested → does NOT pipeline (revises the +24% projection)

    Implemented the frame-level ping-pong overlap (Approach A) on the attached ESP32-P4 and measured it directly. It does not reduce per-frame time. Draft PR: #2521 (do-not-merge).

    Measurement (16×256, debug build, via measureParlio with a new pipelined_per_frame_us metric)

    pipelined_per_frame_us = 31772   ==   total_avg_us (serialized show()+wait()) = 31772
    show_avg_us(encode) = 25449       wire drain ≈ 6.3ms
    

    A tight show()-only loop (the case the overlap should help) gives the same per-frame time as serialized show()+wait(). Every show() still pays encode(~25ms) + wire(~6ms): frame N-1's DMA is not draining during frame N's encode.

    Root cause (the key finding)

    ParlioEngine::beginTransmission() performs a mandatory per-frame disable()/enable() of the PARLIO peripheral — documented in-code as required to reset the DMA state machine, "without this, consecutive transmissions with the same config silently fail (0 bytes output)." That teardown serializes frames at the hardware level: the peripheral cannot keep transmitting frame N-1 while it is being reconfigured/re-enabled for frame N. Ping-pong buffering alone cannot overcome this — the bottleneck is the peripheral reset, not the buffer count.

    Revised conclusion

    • The earlier Approach-A "+24%" was a projection that hardware did not bear out. For the current driver structure, the single-full-frame path (post-fix(parlio): size DMA buffers from per-lane input bytes #2519) is effectively the practical maximum for the given memory — extra buffers don't help while the per-frame disable/enable stands.
    • Real frame-level overlap requires a deeper change: eliminate/relax the per-frame disable()/enable() so the peripheral can pipeline consecutive frames (this is the actual blocker; it interacts with the same DMA-seam/reset constraints discussed above). Failing that, the remaining lever is a faster encoder (SIMD / second core), which is orthogonal to memory.
    • Net: this is the honest "max perf for current memory" answer — it's already there; the next win is architectural (peripheral pipelining) or encode-side (SIMD), not buffering.

    Status / caveats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions