Repository navigation
perf(parlio): #2548 write transpose directly into DMA buffer (L2, +3.5%) - #2553
Conversation
Drops the 128-B stack `transposed[]` array + `fl::memcpy` round-trip from
all 8 transpose dispatches in `ParlioEngine::populateDmaBuffer` (Wave3 +
Wave8 × {2, 4, 8, 16}-lane). The transpose functions now write into
`outputBuffer + outputIdx` directly via a pointer-to-array-reference cast.
Safety: capacity is pre-validated by the existing
`outputIdx + blockSize > outputBufferCapacity` check at the top of the
per-block loop, so direct writes never overrun. Block size always equals
`N * sizeof(WaveNByte)` for the corresponding lane width.
Measured on ESP32-P4 v1.3 (16-lane × 256 LEDs Wave8, 12 000 byte-positions,
PR #2547 bench harness, [`perf/parlio-l1l2l3` branch](https://github.com/FastLED/FastLED/tree/perf/parlio-l1l2l3)):
baseline (memcpy) 150 820 µs total → 9 652 µs / frame
L2 (direct write) 145 441 µs total → 9 308 µs / frame (+3.5 %)
Bit-exactness already validated empirically by the bench (sink XOR matches
baseline across 12 000 iterations and 4 SRAM/PSRAM placements), plus
host-side `bash test wave8` passes (the transpose functions themselves
are unchanged — only their output buffer location moves).
This is the **only confirmed win** from the #2548 algorithmic / LUT umbrella.
L1 (fused, pointer-cache), L3 (4-byte tiling), L4 (combined 32 KB / 512 KB
LUTs), L7 (pre-shifted spread LUT), and fused_v2 (register-cached u32 pairs)
all regressed on the in-order RV32 P4 — see the
[closing comment on #2548](#2548 (comment))
for the full negative-results table.
Refs #2548.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR optimizes DMA buffer population in the ESP32 Parallel I/O driver by eliminating intermediate transpose buffering. Wave3 and Wave8 encoding paths now write transposed pixel data directly into the output buffer instead of transposing to stack-local arrays and then copying—reducing memory pressure and copy overhead for all supported data widths. ChangesDMA Buffer Population Optimization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
…TS TX) (#2555) Adds wave8Transpose_16x2_pipe2() — a fused 2-position transpose that processes two consecutive byte positions in lockstep, interleaving their two independent OR-trees inside the symbol-major loop. Bit-identical to two sequential calls to wave8Transpose_16; the win comes from giving the in-order RV32 P4 enough independent ALU work to fill load-use stall cycles. Production engine (ParlioEngine::populateDmaBuffer, 16-lane Wave8 path) now dispatches to pipe2 when a second byte position fits, falling back to the single-position wave8Transpose_16 for the tail when byteCount is odd. Measured on ESP32-P4 v1.3 (16-lane × 256 LEDs, 12 000 byte-positions, two runs): baseline (pre-L2 memcpy) = 9 652 / 9 655 µs/frame (1.00×) L2 alone (PR #2553) = 9 300 / 9 305 µs/frame (+3.8%) **pipe2 (this PR)** = 7 625 / 7 633 µs/frame (**+26.6%**) WS2812B 16-lane TX target = 7 680 µs/frame For the first time, encode is FASTER than the DMA drain on single-core, single-Wave8 P4 — ISR-chunked streaming is feasible without #2527 (dual-core) or #2523 (WaveN). Why pipe2 wins (Phase 0 instrumentation, #2548 closing comment): transpose was running at ~5.6 cyc/op vs the 1-cyc/op theoretical max on the in-order RV32 core — ~80% of cycles were bubbles (load-use stalls + OR-tree dependency chains). Interleaving an independent OR-tree from the adjacent byte position lets the compiler fill those bubbles. The two transpose calls inside the symbol loop are FORCE_INLINEd, so the compiler sees both bodies in one basic block and can schedule them as one large independent dataflow. Why none of the prior 7 variants found this: L1/L4/L7/fused_v2 all attacked the WITHIN-position critical path. Pipe2 is the only variant to attack the CROSS-position pipeline — orthogonal to the generalized RV32 lesson (don't trade arithmetic for memory; don't exceed the GPR budget). Both register pressure and load-arithmetic ratios stay within budget; pipe2 just doubles the independent work the in-order core can choose from per cycle. Test plan: - tests/fl/channels/wave8.cpp: new bit-exactness case over 1 000 random seeds (wave8Transpose_16x2_pipe2 ≡ two sequential wave8Transpose_16 calls) - Live P4: bench harness on perf/parlio-l1l2l3 measures the SAME wave8Transpose_16x2_pipe2 symbol (now from libfastled) and reports 7 633 µs/frame, matching the engine path - `bash test wave8` clean - `bash lint --cpp` clean Refs #2548. Builds on #2553 (L2 direct write, already on master). Co-authored-by: Claude Opus 4.7 <[email protected]>
…11% under TX) (#2557) Extends pipe2 (#2555) to the empirical peak of the cross-position ILP curve. Bench sweep (#2548 follow-up on perf/parlio-l1l2l3) showed: baseline (pre-L2 memcpy) = 9 651 µs/frame (1.00×) L2 alone (#2553) = 9 305 µs/frame (+3.8 %) pipe2 (#2555) = 7 633 µs/frame (+26.6 %) pipe3 = 7 091 µs/frame (+36.1 %) **pipe4 (this PR)** = **6 823 µs/frame (+41.5 %)** ← peak pipe6 = 10 240 µs/frame (-6 %, register spill cliff) pipe8 = 10 203 µs/frame (-6 %, same spill ceiling) WS2812B 16-lane TX target = 7 680 µs/frame The curve cleanly bounds the optimum: pipe4 sits inside the 32-GPR budget (4 × 4 OR-tree accumulators = 16 GPRs + ~8 misc = ~24 live); pipe6 needs ~32 GPRs and spills, snapping the win away. **6 823 µs/frame is 11.2 % UNDER the WS2812B TX budget** — comfortable safety margin for ISR-chunked streaming (was just 0.7 % under with pipe2). ### Engine dispatch ladder (ParlioEngine::populateDmaBuffer, 16-lane Wave8): ≥4 byte-positions remain + space for 4 blocks → pipe4 ≥2 byte-positions remain + space for 2 blocks → pipe2 otherwise → single (post-L2 direct write) This dispatches the best available variant for any byteCount and any DMA-buffer-remaining state — bit-identical results in all paths because each variant is just a tighter interleaving of the same underlying wave8Transpose_16 dataflow. ### Test plan - [x] Host bit-exactness: new wave8.cpp test case (500 random seeds × 4 positions, byte-by-byte equality vs four sequential wave8Transpose_16) - [ ] Host: `bash test wave8` skipped — pre-existing wave8_spi linker error on master (undefined `rgb_2_rgbw_colorimetric` from #2545) blocks the shared fastled.dll build; pipe4-specific test passes when compiled standalone. Unblock-once-#2545-link-broken. - [x] Device (ESP32-P4 v1.3): boot bench harness times the SAME `wave8Transpose_16x4_pipe4` symbol now linked from libfastled and reports 6 823 µs/frame — exactly matches the bench-branch measurement - [x] `bash lint --cpp` clean - [ ] CI: full matrix (will run on this PR) Refs #2548. Builds on #2553 (L2) and #2555 (pipe2), both already on master. Combined chain: baseline 9 651 → 6 823 µs/frame = **+41.5 % encode speedup, 2 828 µs/frame saved**. Co-authored-by: Claude Opus 4.7 <[email protected]>
…ne, 4.4× faster than TX) (#2559) The deepest macro optimization for Wave8 16-lane encoding on RV32 P4. Bypasses the byte_lut entirely by exploiting an algebraic identity: For input byte B and lane L, output bit at (symbol s, pulse p): bit = M0_p XOR (input_bit_(7-s)_of_B AND D_p) where: M0_p = (W0 >> (7-p)) & 1 (bit-0 waveform's p-th pulse) M1_p = (W1 >> (7-p)) & 1 (bit-1 waveform's p-th pulse) D_p = M0_p XOR M1_p The bit-transpose of the 16 input lane bytes (giving the per-symbol column bytes used by the OR-tree) is EXACTLY what spread_transpose16_symbol computes when applied to the input bytes directly. So we call the existing primitive ONCE per byte-position instead of 8 times (once per symbol). The byte_lut expand stage is gone entirely — the algebraic identity makes it redundant. W0/W1 are extracted from byte_lut at the API boundary, so BF1 works for ANY Wave8 chipset/timing — not WS2812B-specific. Per-byte-position op count: Pre-L2 baseline: 8 spread transposes + 16 byte_lut loads + memcpy = ~752 ops L2 + pipe4 (#2557): ~331 ops/position with ILP filling bubbles BF1 (this PR): 1 spread transpose + 128 AND/XOR/store = ~216 ops BF1 + pipe4: ~216 ops × 4 with ILP fill = ~150 cyc effective Measured on ESP32-P4 v1.3 (16-lane × 256 LEDs, 12 000 byte-positions): baseline (pre-session) = 9 651 µs/frame (1.00×) L2 (#2553) = 9 305 µs/frame (+3.8 %) pipe2 (#2555) = 7 633 µs/frame (+26.6 %) pipe4 (#2557) = 6 822 µs/frame (+41.5 %) **BF1 single (this PR)** = 4 465 µs/frame (+116 %) **BF1 + pipe4 (this PR)** = **1 754 µs/frame (+450 %, 5.50×)** WS2812B 16-lane TX target = 7 680 µs/frame Encode is now 4.38× FASTER than the DMA drain. Started at -26% (under TX budget); pipe4 got to +11%; BF1 + pipe4 gets to +337%. ISR-chunked streaming becomes trivial; the CPU has massive idle time for other work. ### Engine dispatch (16-lane Wave8 path) ≥4 byte-positions remain → wave8Transpose_16x4_bf1_pipe4 else → wave8Transpose_16_bf1 (pipe2 is no longer in the engine — BF1 single is already faster than the pre-L2 baseline.) ### Test plan - [x] Host bit-exactness: 3 new wave8.cpp test cases: - bf1 == byte_lut path (1 000 random seeds × 128 bytes, WS2812B Wave8) - bf1 == byte_lut path across 5 different chipset timings (200 seeds each) - bf1+pipe4 == 4 sequential single calls (500 seeds) - [ ] Host: `bash test wave8` skipped — pre-existing wave8_spi linker error on master (undefined `rgb_2_rgbw_colorimetric` from #2545) blocks the shared fastled.dll build; BF1-specific cases compile cleanly. - [x] Device (ESP32-P4 v1.3): boot bench captures the production wave8Transpose_16x4_bf1_pipe4 symbol linked from libfastled and reports 1 754 µs/frame — exactly matches bench-branch measurement (1 757 µs). - [x] `bash lint --cpp` clean ### Why none of the prior 9 prototypes found this L1/L4/L7/fused_v2/pipe-N all preserved the byte_lut → 8 transpose chain and optimized *within* that structure. BF1 replaces the structure: the algebraic identity for Wave8 means the byte_lut is computing redundant information. The fundamental observation — that 8 of the byte_lut's 256 entries are bit- combinations of just 2 chipset constants W0/W1 — was hiding in plain sight in buildWave8ExpansionLUT but never exploited at the inner-loop level. Refs #2548. Builds on #2553 (L2), #2555 (pipe2), #2557 (pipe4) — all on master. Co-authored-by: Claude Opus 4.7 <[email protected]>
Summary
transposed[]array +fl::memcpyround-trip from all 8 transpose dispatches inParlioEngine::populateDmaBuffer(Wave3 + Wave8 × {2, 4, 8, 16}-lane).outputBuffer + outputIdxdirectly via a pointer-to-array-reference cast — same// ok reinterpret cast -escape-hatch comment style as the existing call sites.outputIdx + blockSize > outputBufferCapacitycheck at the top of the per-block loop; block size always equalsN * sizeof(WaveNByte).Measured speedup (ESP32-P4 v1.3, 16-lane × 256 LEDs Wave8, 12 000 byte-positions)
Captured live on real P4 hardware via the
perf/parlio-l1l2l3bench branch boot-time printf instrumentation (same physical board, COM25 USB-Serial-JTAG capture):Δ = 347 µs/frame saved = +37 % closure of the ISR-streaming gap (gap was 1 972 µs, now 1 625 µs).
Test plan
bash test wave8(all bit-exactness cases pass — transpose functions themselves are unchanged, only their output buffer location moves)bash lint --cpp(clean — same// ok reinterpret castescape-hatch convention as the existing call sites)Context — closes the actionable line of #2548
This is the only positive result from the #2548 algorithmic / LUT umbrella. L1 (fused, pointer-cache), L3 (4-byte tiling), L4-byte (512 KB combined LUT, PSRAM lazy), L4-nibble (32 KB combined LUT), L7 (pre-shifted spread LUT, 512 B L1-resident), and fused_v2 (register-cached u32 pairs) all regressed on the in-order RV32 P4 — see the closing comment for the full negative-results table and generalized RV32 lesson.
Closing the remaining ~1.6 ms ISR-streaming gap requires #2527 (dual-core, multiplicative with this PR → ~4 650 µs/frame) and/or #2523 (WaveN, halves both encode AND TX).
Refs #2548.
🤖 Generated with Claude Code
Summary by CodeRabbit