Skip to content

perf(parlio): bench encode hot loop with SRAM/PSRAM placements - #2547

Merged
zackees merged 1 commit into
masterfrom
perf/parlio-encode-bench
May 29, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/parlio-encode-bench

Conversation

@zackees

@zackees zackees commented May 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds parlioEncodeBenchmark (RPC handler + boot-time bridge via FL_BENCH_PARLIO_AT_BOOT) that replicates the engine's per-byte-position hot loop and times it across SRAM/PSRAM placements for both scratch and output. Mirrors the pattern from #2539's wave8ExpandBenchmark.

This is a measurement tool — no production code path changes.

Why

The byte-LUT (#2526/#2539) shipped, and the open question was:

  1. Is the encode now fast enough for ISR-driven chunked streaming?
  2. Is PSRAM still part of the bottleneck story?

Measured on ESP32-P4 v1.3 (16-lane × 256-LED config, 12,000 byte-positions)

perpos_us     ss=150804 sp=149812 ps=149931 pp=149815
perpos_ns     ss=12567  sp=12484  ps=12494  pp=12484
frame_equiv   ss=9651   sp=9587   ps=9595   pp=9588
ratio_x100    sp/ss=99  ps/ss=99  pp/ss=99
ws2812b_tx_us=7680
  • PSRAM hypothesis denied: all four placements within ~0.7% (L2 cache fully hides PSRAM latency). Matches the prior session's ×1.00 measurement; do not chase PSRAM theories.
  • ISR streaming not yet feasible: encode 9.65 ms vs TX 7.68 ms per frame — CPU is ~26% slower than DMA. Need encode ≤ 7.68 ms (ideally ≤ 6 ms with margin).
  • Recommended next lever: dual-core encode (Wave8 opt: dual-core encode on ESP32-P4 #2527) — should push encode → ~5.4 ms, comfortably under TX.

Full analysis posted to #2526.

Test plan

Refs #2526, #2527 (dual-core, the recommended next lever), #2525, #2523, #2541

Summary by CodeRabbit

  • New Features
    • Added PARLIO encoding benchmarking for ESP32-P4 with optional boot-time measurement capability
    • New remote RPC endpoint for performance analysis providing detailed timing metrics across multiple memory placements
    • Includes per-iteration and frame-level timing comparisons between SRAM and PSRAM configurations

Review Change Stack

Mirrors the AutoResearchWave8Expand pattern. Replicates the engine's
per-byte-position hot path (16-lane gather + wave8Transpose_16 + memcpy 128B)
and times 4 placements of {scratch, output} across SRAM/PSRAM. Frame-
equivalent is x768 byte-positions = 16-channel x 256-LED frame.

RPC-driven via parlioEncodeBenchmark in AutoResearchRemote.cpp (off by
default at boot, behind -DFL_BENCH_PARLIO_AT_BOOT=1). Output via
esp_rom_printf to COM25 until #2541 routing fix lands.

Measured on ESP32-P4 v1.3 (boot-time bridge), 12000 byte-positions per
placement:

  perpos_us  ss=150804 sp=149812 ps=149931 pp=149815
  perpos_ns  ss=12567  sp=12484  ps=12494  pp=12484
  frame_equiv ss=9651  sp=9587   ps=9595   pp=9588
  ratio_x100  sp/ss=99 ps/ss=99  pp/ss=99
  ws2812b_tx_us=7680 (256 LEDs * 24 bits * 1.25us/bit)

So PSRAM and SRAM are within ~0.7% (the L2 cache fully hides PSRAM latency
for this access pattern — confirms the prior session's x1.00 finding).
Encode 9.65 ms/frame vs TX 7.68 ms/frame -> not yet fast enough for
ISR-chunked streaming (CPU produces ~26% slower than DMA drains).

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

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR adds a PARLIO byte-position encode micro-benchmark for ESP32-P4, measuring timing across four memory placement combinations (SRAM-only, SRAM scratch + PSRAM output, PSRAM scratch + SRAM output, dual-PSRAM). The benchmark is callable at boot-time and via RPC, with results printed as microsecond timings and PSRAM-to-SRAM ratios.

Changes

PARLIO Encode Micro-Benchmark

Layer / File(s) Summary
Benchmark Implementation
examples/AutoResearch/AutoResearchParlioEncode.h
Defines ParlioEncodeResult struct with timing fields for four memory modes; implements hot-path loop mirror (16-lane gather + transpose + memcpy) for IRAM; allocates scratch/output buffers in SRAM/PSRAM; measures encode-like operations across four placement combinations; prints derived per-iteration and frame timings plus PSRAM-to-SRAM ratios via esp_rom_printf; provides disabled stubs when benchmark is gated off.
Boot-Time Execution
examples/AutoResearch/AutoResearch.ino
Includes benchmark header; inserts compile-gated setup() call to measureParlioEncode() and printParlioEncodeResultRom() for boot-time measurement when FL_BENCH_PARLIO_AT_BOOT is defined.
RPC Framework Integration
examples/AutoResearch/AutoResearchRemote.cpp
Includes benchmark header; registers new parlioEncodeBenchmark RPC handler that accepts optional iterations parameter, invokes measurement, and returns JSON with timing metrics and configuration sizes; updates help RPC to list new function.

Sequence Diagram

sequenceDiagram
  participant Boot as Setup/RPC
  participant Measure as measureParlioEncode
  participant Alloc as heap_caps_malloc
  participant HotPath as Measurement
  participant Print as printParlioEncodeResultRom
  
  Boot->>Measure: invoke with iterations
  Measure->>Alloc: allocate scratch SRAM
  Alloc-->>Measure: scratch_sram ptr
  Measure->>Alloc: allocate output SRAM
  Alloc-->>Measure: output_sram ptr
  Measure->>Alloc: allocate scratch PSRAM
  Alloc-->>Measure: scratch_psram ptr
  Measure->>Alloc: allocate output PSRAM
  Alloc-->>Measure: output_psram ptr
  
  Measure->>Measure: initialize scratch/output
  Measure->>HotPath: warm-up measurement
  HotPath-->>Measure: warm-up timing
  
  Measure->>HotPath: measure SS (scratch SRAM, output SRAM)
  HotPath-->>Measure: ss_us timing
  Measure->>HotPath: measure SP (scratch SRAM, output PSRAM)
  HotPath-->>Measure: sp_us timing
  Measure->>HotPath: measure PS (scratch PSRAM, output SRAM)
  HotPath-->>Measure: ps_us timing
  Measure->>HotPath: measure PP (scratch PSRAM, output PSRAM)
  HotPath-->>Measure: pp_us timing
  
  Measure->>Measure: free all buffers
  Measure-->>Boot: ParlioEncodeResult
  
  Boot->>Print: printParlioEncodeResultRom(result)
  Print->>Print: compute per-iteration ns
  Print->>Print: compute frame-equivalent us
  Print->>Print: compute PSRAM/SRAM ratios
  Print-->>Boot: printed via esp_rom_printf
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Poem

🐰 A benchmark hops forth with flair,
PARLIO timing, SRAM/PSRAM care—
Gather, transpose, memcpy dance,
At boot and RPC, measurement's chance! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf(parlio): bench encode hot loop with SRAM/PSRAM placements' accurately summarizes the main change—adding a benchmarking tool that measures PARLIO encode performance across different memory placements.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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-encode-bench

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
examples/AutoResearch/AutoResearchParlioEncode.h (1)

89-110: 💤 Low value

Consider validating buffer sizes for defensive programming.

The parameters scratch_size and output_size are marked unused (lines 97-98) but could be validated against the expected access pattern:

  • Max scratch access: 15 * lane_stride + byte_offset ≤ scratch_size
  • Max output access: output_idx + 127 ≤ output_size

Since fl_parlio_measure is internal and only called with correct sizes from measureParlioEncode, the current approach is acceptable. However, adding assertions would catch future refactoring errors.

🛡️ Optional defensive checks
 inline fl::u32 fl_parlio_measure(const fl::u8 *scratch, fl::size_t scratch_size,
                                  fl::u8 *output, fl::size_t output_size,
                                  const fl::Wave8ByteExpansionLut &byte_lut,
                                  int iters_byte_positions,
                                  volatile fl::u32 *sink) {
     constexpr fl::size_t LANES = 16;
     constexpr fl::size_t BYTES_PER_LANE = 768; // 256 LEDs × 3
     const fl::size_t lane_stride = BYTES_PER_LANE;
-    (void)scratch_size;
-    (void)output_size;
+    // Defensive validation (could be ifdef DEBUG)
+    const fl::size_t min_scratch = LANES * BYTES_PER_LANE;
+    const fl::size_t min_output = BYTES_PER_LANE * LANES * sizeof(fl::Wave8Byte);
+    if (scratch_size < min_scratch || output_size < min_output) {
+        return 0; // Caller checks for zero timing
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/AutoResearch/AutoResearchParlioEncode.h` around lines 89 - 110,
fl_parlio_measure currently ignores scratch_size and output_size but computes
indices that can read/write beyond buffers; add defensive checks (assertions or
early returns) in fl_parlio_measure to validate that scratch_size >= (LANES - 1)
* lane_stride + BYTES_PER_LANE (i.e., max scratch index = 15*lane_stride +
(BYTES_PER_LANE-1)) and output_size >= (BYTES_PER_LANE - 1) * LANES *
sizeof(fl::Wave8Byte) + sizeof(fl::Wave8Byte) (i.e., ensure output_idx + max
Wave8Byte size ≤ output_size) before the loop, referencing LANES,
BYTES_PER_LANE, lane_stride, byte_offset, and output_idx computations so any
future refactor trips the check instead of UB.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@examples/AutoResearch/AutoResearchParlioEncode.h`:
- Around line 89-110: fl_parlio_measure currently ignores scratch_size and
output_size but computes indices that can read/write beyond buffers; add
defensive checks (assertions or early returns) in fl_parlio_measure to validate
that scratch_size >= (LANES - 1) * lane_stride + BYTES_PER_LANE (i.e., max
scratch index = 15*lane_stride + (BYTES_PER_LANE-1)) and output_size >=
(BYTES_PER_LANE - 1) * LANES * sizeof(fl::Wave8Byte) + sizeof(fl::Wave8Byte)
(i.e., ensure output_idx + max Wave8Byte size ≤ output_size) before the loop,
referencing LANES, BYTES_PER_LANE, lane_stride, byte_offset, and output_idx
computations so any future refactor trips the check instead of UB.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b8624221-0d68-4589-8004-56c26fc3cf15

📥 Commits

Reviewing files that changed from the base of the PR and between 45ad707 and 6d94b1a.

📒 Files selected for processing (3)
  • examples/AutoResearch/AutoResearch.ino
  • examples/AutoResearch/AutoResearchParlioEncode.h
  • examples/AutoResearch/AutoResearchRemote.cpp

@zackees
zackees merged commit 56bf1e8 into master May 29, 2026
5 of 7 checks passed
zackees added a commit that referenced this pull request May 29, 2026
…tive result

Layered on perf/parlio-l1l2l3. Adds the L4 (combined byte+lane+symbol LUT)
variant from #2548, allocated lazily from PSRAM (Wave8L4LutSpan = fixed-extent
fl::span<u8, 524288>) to address the original SRAM-commitment deferral.

Structure: lut[8 symbols][16 lanes][256 bytes][16 output bytes] = 512 KB,
built via spread_transpose16_symbol on dummy lanes (correct by construction),
kernel does 8-symbol x 16-lane x 4-u32 OR-reduce per byte_position.

Measured on ESP32-P4 v1.3 with the LUT in PSRAM and the kernel reading
through L2 cache (which has decisively hidden PSRAM for every other PARLIO
access pattern in #2547):

  baseline_us  =150858  frame=9654  (1.00x)
  L4_psram_us  =1081675 frame=69227 speedup_x100=13  (0.13x, 7.7x SLOWER)

512 KB LUT does NOT fit in the P4's 128 KB L2 cache. Per byte_position the
kernel touches 128 distinct (lane, byte) entries that evict each other from
L2; each miss hits PSRAM directly. PSRAM cache-miss latency dominates and
crushes the op-count algorithmic savings, exactly the opposite of every other
PARLIO access pattern (#2547).

The same applies to *any* L4-class LUT large enough to cover all 8 symbols
(natural lower bound is ~512 KB; shrinking to 64 KB requires dropping the
symbol dimension, at which point the structure collapses back to L7).

Lazy/PSRAM allocation as a *technique* still works for smaller LUTs (e.g.
L7 at 1 KB) — but L4 specifically can't be rescued by it.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request May 30, 2026
)

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]>
zackees added a commit that referenced this pull request May 30, 2026
…only

Layered on top of PR #2547. Adds three #2548 algorithmic variants to the
parlioEncodeBenchmark (all SRAM/SRAM so the algorithm is isolated):

- L2:        direct write to output, skip the engine's 128-B memcpy
- L1+L2:     fused expand+transpose (cached byte_lut row pointers)
             + direct write
- L1+L2+L3:  fused + direct write + 4-byte-position tiling

Extends ParlioEncodeResult, the BENCH_PARLIO esp_rom_printf output, and the
parlioEncodeBenchmark RPC payload.

Measured on ESP32-P4 v1.3 (12,000 byte-positions each):
  baseline_us  =150790  frame=9650  (1.00x)
  L2_us        =145441  frame=9308  (1.03x  ~3.5%)
  L1+L2_us     =152148  frame=9737  (0.99x  REGRESSION)
  L1+L2+L3_us  =147556  frame=9443  (1.02x  ~2%)
  ws2812b_tx_us=7680

L1 fusion is counterproductive on RV32: 16 cached byte_lut row pointers
exceed the 32-GPR budget, spilling more than the intermediate buffer they
eliminate. Baseline's laneWaveformSymbols[16] is already an effective
L1-cached register-file extension.

L2 (skip memcpy) helps ~3.5%, but on its own doesn't close the ~2 ms/frame
ISR-streaming gap. Re-evaluation posted to #2548. No production wiring
shipped from this measurement.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request May 30, 2026
…tive result

Layered on perf/parlio-l1l2l3. Adds the L4 (combined byte+lane+symbol LUT)
variant from #2548, allocated lazily from PSRAM (Wave8L4LutSpan = fixed-extent
fl::span<u8, 524288>) to address the original SRAM-commitment deferral.

Structure: lut[8 symbols][16 lanes][256 bytes][16 output bytes] = 512 KB,
built via spread_transpose16_symbol on dummy lanes (correct by construction),
kernel does 8-symbol x 16-lane x 4-u32 OR-reduce per byte_position.

Measured on ESP32-P4 v1.3 with the LUT in PSRAM and the kernel reading
through L2 cache (which has decisively hidden PSRAM for every other PARLIO
access pattern in #2547):

  baseline_us  =150858  frame=9654  (1.00x)
  L4_psram_us  =1081675 frame=69227 speedup_x100=13  (0.13x, 7.7x SLOWER)

512 KB LUT does NOT fit in the P4's 128 KB L2 cache. Per byte_position the
kernel touches 128 distinct (lane, byte) entries that evict each other from
L2; each miss hits PSRAM directly. PSRAM cache-miss latency dominates and
crushes the op-count algorithmic savings, exactly the opposite of every other
PARLIO access pattern (#2547).

The same applies to *any* L4-class LUT large enough to cover all 8 symbols
(natural lower bound is ~512 KB; shrinking to 64 KB requires dropping the
symbol dimension, at which point the structure collapses back to L7).

Lazy/PSRAM allocation as a *technique* still works for smaller LUTs (e.g.
L7 at 1 KB) — but L4 specifically can't be rescued by it.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request May 30, 2026
…only

Layered on top of PR #2547. Adds three #2548 algorithmic variants to the
parlioEncodeBenchmark (all SRAM/SRAM so the algorithm is isolated):

- L2:        direct write to output, skip the engine's 128-B memcpy
- L1+L2:     fused expand+transpose (cached byte_lut row pointers)
             + direct write
- L1+L2+L3:  fused + direct write + 4-byte-position tiling

Extends ParlioEncodeResult, the BENCH_PARLIO esp_rom_printf output, and the
parlioEncodeBenchmark RPC payload.

Measured on ESP32-P4 v1.3 (12,000 byte-positions each):
  baseline_us  =150790  frame=9650  (1.00x)
  L2_us        =145441  frame=9308  (1.03x  ~3.5%)
  L1+L2_us     =152148  frame=9737  (0.99x  REGRESSION)
  L1+L2+L3_us  =147556  frame=9443  (1.02x  ~2%)
  ws2812b_tx_us=7680

L1 fusion is counterproductive on RV32: 16 cached byte_lut row pointers
exceed the 32-GPR budget, spilling more than the intermediate buffer they
eliminate. Baseline's laneWaveformSymbols[16] is already an effective
L1-cached register-file extension.

L2 (skip memcpy) helps ~3.5%, but on its own doesn't close the ~2 ms/frame
ISR-streaming gap. Re-evaluation posted to #2548. No production wiring
shipped from this measurement.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request May 30, 2026
…tive result

Layered on perf/parlio-l1l2l3. Adds the L4 (combined byte+lane+symbol LUT)
variant from #2548, allocated lazily from PSRAM (Wave8L4LutSpan = fixed-extent
fl::span<u8, 524288>) to address the original SRAM-commitment deferral.

Structure: lut[8 symbols][16 lanes][256 bytes][16 output bytes] = 512 KB,
built via spread_transpose16_symbol on dummy lanes (correct by construction),
kernel does 8-symbol x 16-lane x 4-u32 OR-reduce per byte_position.

Measured on ESP32-P4 v1.3 with the LUT in PSRAM and the kernel reading
through L2 cache (which has decisively hidden PSRAM for every other PARLIO
access pattern in #2547):

  baseline_us  =150858  frame=9654  (1.00x)
  L4_psram_us  =1081675 frame=69227 speedup_x100=13  (0.13x, 7.7x SLOWER)

512 KB LUT does NOT fit in the P4's 128 KB L2 cache. Per byte_position the
kernel touches 128 distinct (lane, byte) entries that evict each other from
L2; each miss hits PSRAM directly. PSRAM cache-miss latency dominates and
crushes the op-count algorithmic savings, exactly the opposite of every other
PARLIO access pattern (#2547).

The same applies to *any* L4-class LUT large enough to cover all 8 symbols
(natural lower bound is ~512 KB; shrinking to 64 KB requires dropping the
symbol dimension, at which point the structure collapses back to L7).

Lazy/PSRAM allocation as a *technique* still works for smaller LUTs (e.g.
L7 at 1 KB) — but L4 specifically can't be rescued by it.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request May 30, 2026
…only

Layered on top of PR #2547. Adds three #2548 algorithmic variants to the
parlioEncodeBenchmark (all SRAM/SRAM so the algorithm is isolated):

- L2:        direct write to output, skip the engine's 128-B memcpy
- L1+L2:     fused expand+transpose (cached byte_lut row pointers)
             + direct write
- L1+L2+L3:  fused + direct write + 4-byte-position tiling

Extends ParlioEncodeResult, the BENCH_PARLIO esp_rom_printf output, and the
parlioEncodeBenchmark RPC payload.

Measured on ESP32-P4 v1.3 (12,000 byte-positions each):
  baseline_us  =150790  frame=9650  (1.00x)
  L2_us        =145441  frame=9308  (1.03x  ~3.5%)
  L1+L2_us     =152148  frame=9737  (0.99x  REGRESSION)
  L1+L2+L3_us  =147556  frame=9443  (1.02x  ~2%)
  ws2812b_tx_us=7680

L1 fusion is counterproductive on RV32: 16 cached byte_lut row pointers
exceed the 32-GPR budget, spilling more than the intermediate buffer they
eliminate. Baseline's laneWaveformSymbols[16] is already an effective
L1-cached register-file extension.

L2 (skip memcpy) helps ~3.5%, but on its own doesn't close the ~2 ms/frame
ISR-streaming gap. Re-evaluation posted to #2548. No production wiring
shipped from this measurement.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request May 30, 2026
…tive result

Layered on perf/parlio-l1l2l3. Adds the L4 (combined byte+lane+symbol LUT)
variant from #2548, allocated lazily from PSRAM (Wave8L4LutSpan = fixed-extent
fl::span<u8, 524288>) to address the original SRAM-commitment deferral.

Structure: lut[8 symbols][16 lanes][256 bytes][16 output bytes] = 512 KB,
built via spread_transpose16_symbol on dummy lanes (correct by construction),
kernel does 8-symbol x 16-lane x 4-u32 OR-reduce per byte_position.

Measured on ESP32-P4 v1.3 with the LUT in PSRAM and the kernel reading
through L2 cache (which has decisively hidden PSRAM for every other PARLIO
access pattern in #2547):

  baseline_us  =150858  frame=9654  (1.00x)
  L4_psram_us  =1081675 frame=69227 speedup_x100=13  (0.13x, 7.7x SLOWER)

512 KB LUT does NOT fit in the P4's 128 KB L2 cache. Per byte_position the
kernel touches 128 distinct (lane, byte) entries that evict each other from
L2; each miss hits PSRAM directly. PSRAM cache-miss latency dominates and
crushes the op-count algorithmic savings, exactly the opposite of every other
PARLIO access pattern (#2547).

The same applies to *any* L4-class LUT large enough to cover all 8 symbols
(natural lower bound is ~512 KB; shrinking to 64 KB requires dropping the
symbol dimension, at which point the structure collapses back to L7).

Lazy/PSRAM allocation as a *technique* still works for smaller LUTs (e.g.
L7 at 1 KB) — but L4 specifically can't be rescued by it.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
zackees added a commit that referenced this pull request May 30, 2026
…e to RPC (#2562)

Removes the `FL_PARLIO_STREAM_VALIDATE_AT_BOOT` boot-time hook landed in
#2561 and re-exposes the same functional test as a JSON-RPC handler
`parlioStreamValidate`, matching the convention of the other autoresearch
utility benches (`wave8ExpandBenchmark` #2539, `parlioEncodeBenchmark` #2547).

### Changes

- `AutoResearchParlioStream.h`:
  - `validateAtBoot()` (esp_rom_printf-based) → `validateParlioStreaming()`
    returning a `ValidateResult` struct (channels_ok, completed, per_iter_us[],
    steady_avg_us, failed_iter, etc.).
  - Caller-supplied `num_lanes`, `num_leds`, `iterations`, `timeout_ms` so the
    RPC can drive different workloads.
  - Static LED buffer sized for the canonical worst case (16 × 256) to avoid
    repeated allocation across RPC calls.

- `AutoResearch.ino`:
  - Drop the `#ifdef FL_PARLIO_STREAM_VALIDATE_AT_BOOT` boot-time hook.
  - Keep the header include for the RPC handler in AutoResearchRemote.cpp.

- `AutoResearchRemote.cpp`:
  - Add `parlioStreamValidate` bind: parses optional `numLanes`/`numLeds`/
    `iterations`/`timeoutMs` from args, calls `validateParlioStreaming()`,
    returns full result as JSON (`channelsOk`, `completed`, `lanes`,
    `ledsPerLane`, `iterations`, `perIterUs:[…]`, `steadyAvgUs`, `failedIter`,
    `timeoutMs`).
  - Register in `discoverFunctions` metadata (totalFunctions 24 → 25, Phase 4
    Utility, full args + returns docstring).

### Validation

- `bash lint --cpp` clean
- Build + flash on ESP32-P4 v1.3 (`bash autoresearch esp32p4 --simd --no-fbuild`)
  succeeds; handler is registered.
- On-device RPC invocation is blocked on P4 by the pre-existing
  #2541 (testSimd RPC over UART0 fails because the host connects via COM25
  USB-Serial-JTAG, different physical path). Same blocker that already affects
  `testSimd`, `wave8ExpandBenchmark`, and `parlioEncodeBenchmark`. The
  handler will be invokable from CI / other platforms once that infra
  issue is resolved.
- Functional correctness was previously demonstrated end-to-end via the
  boot-time variant in #2561: 5 back-to-back show()+wait() iterations,
  16-lane × 256-LED WS2812B, all completed within timeout (steady-state
  ~17 ms/frame, 0 hangs).

Refs #2548, #2541. Supersedes the boot-time hook from #2561.

Co-authored-by: Claude Opus 4.7 <[email protected]>
@zackees
zackees deleted the perf/parlio-encode-bench 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