Repository navigation
perf(wave8): byte-indexed expansion LUT (#2526) — 1.66x on ESP32-P4 - #2539
Conversation
Adds a 256x8 byte-indexed expansion LUT (Wave8ByteExpansionLut, 2 KB) and a single-lookup expansion primitive (wave8_expand_byte) that replaces the two nibble lookups in the hot PARLIO encode path. Same bit-exact output, ~half the per-byte index work — which is the bottleneck because expansion is instruction-issue-bound on the in-order RV32 core, not memory-bandwidth-bound. Integration: - New Wave8ByteExpansionLut type and buildWave8ByteExpansionLUT(nibble) builder. - detail::wave8_expand_byte(b, byteLut, *out): one indexed 8-byte copy. - Byte-LUT overloads of wave8Transpose_2/4/8/16; the PARLIO engine now holds mWave8ByteLut alongside mWave8Lut and routes all 5 hot expansion call sites through it (single-lane + 2/4/8/16-lane multi-lane). - Host test buildWave8ByteExpansionLUT_matches_nibble_path verifies bit-exact equivalence across all 256 input bytes. Measured on a real ESP32-P4 (revision v1.3) via a boot-time micro-bench in AutoResearch.ino (output via esp_rom_printf -> USB-Serial-JTAG console to sidestep the testSimd RPC's UART0 routing block; see #2536/#2538): iters=30000 (= 480,000 expansions per measurement) nibble_us=350170 byte_us=210419 batched_us=198682 frame_equiv (768 byte-positions): nibble=8964us byte=5386us batched=5086us speedup vs nibble: byte=1.66x batched=1.76x At expansion ~55% of encode, the 1.66x expansion speedup predicts ~1.28x on full encode_us — matching the prediction posted on #2526. Co-Authored-By: Claude Opus 4.7 <[email protected]>
📝 WalkthroughWalkthroughThis PR introduces a byte-indexed Wave8 expansion lookup table optimization for faster LED timing waveform encoding on ESP32. It adds a new ChangesWave8 Byte Expansion Path
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
examples/AutoResearch/AutoResearch.ino (1)
334-335: ⚡ Quick winGate the boot-time benchmark behind an opt-in flag.
This now runs on every AutoResearch boot before the harness reports ready. That adds avoidable startup time and extra benchmark output to normal validation runs, even when nobody is collecting perf numbers.
Suggested change
- // `#2526` expansion micro-bench: prints via esp_rom_printf -> USB-JTAG console. - autoresearch::wave8_bench::runWave8ExpandBenchmark(); + // `#2526` expansion micro-bench: enable only for explicit perf captures. + `#if` defined(FASTLED_RUN_WAVE8_EXPAND_BENCH) + autoresearch::wave8_bench::runWave8ExpandBenchmark(); + `#endif`🤖 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/AutoResearch.ino` around lines 334 - 335, Wrap the boot-time benchmark call autoresearch::wave8_bench::runWave8ExpandBenchmark() behind an opt-in flag so it does not run on every boot; add a configurable check (e.g., a bool config flag or compile-time define like enable_wave8_bench) and only invoke runWave8ExpandBenchmark() when that flag is true (check the flag in AutoResearch.ino before calling the function), thereby preserving current startup behavior unless explicitly enabled.tests/fl/channels/wave8.cpp (1)
81-101: ⚡ Quick winAdd coverage for the new byte-LUT transpose overloads.
This only validates the helper-level expansion equivalence. It does not exercise the new public
wave8Transpose_{2,4,8,16}(..., const Wave8ByteExpansionLut&, ...)overloads that the hot PARLIO path now calls, so a bad overload wiring or lane-order regression would still slip through.Suggested follow-up
+FL_TEST_CASE("wave8 byte-LUT transpose overloads match nibble-LUT overloads") { + ChipsetTiming timing; + timing.T1 = 250; + timing.T2 = 500; + timing.T3 = 250; + + Wave8BitExpansionLut nibble = buildWave8ExpansionLUT(timing); + Wave8ByteExpansionLut byte_lut = buildWave8ByteExpansionLUT(nibble); + + { + uint8_t lanes[2] = {0x3C, 0xA5}; + uint8_t exp[2 * sizeof(Wave8Byte)]; + uint8_t got[2 * sizeof(Wave8Byte)]; + wave8Transpose_2(lanes, nibble, exp); + wave8Transpose_2(lanes, byte_lut, got); + for (int i = 0; i < static_cast<int>(sizeof(exp)); ++i) FL_REQUIRE(got[i] == exp[i]); + } + + // Repeat the same pattern for 4/8/16 lanes with mixed lane values. +}🤖 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 `@tests/fl/channels/wave8.cpp` around lines 81 - 101, The test only checks helper-level expansion equivalence but doesn't exercise the public overloads wave8Transpose_2/4/8/16 that accept a const Wave8ByteExpansionLut&, so add test coverage that calls each public transpose overload with the byteLut you already build (Wave8ByteExpansionLut byteLut = buildWave8ByteExpansionLUT(nibble)) and validate outputs against the nibble-based path; for each b in 0..255, produce the expected transposed output by using the existing nibble expansion helpers (detail::wave8_convert_byte_to_wave8byte / detail::wave8_expand_byte or the public nibble-based transpose overloads) and then call wave8Transpose_2(..., byteLut, ...), wave8Transpose_4(..., byteLut, ...), wave8Transpose_8(..., byteLut, ...), wave8Transpose_16(..., byteLut, ...) comparing returned/transposed buffers element-wise to ensure lane-order and wiring match.
🤖 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/AutoResearch.ino`:
- Around line 334-335: Wrap the boot-time benchmark call
autoresearch::wave8_bench::runWave8ExpandBenchmark() behind an opt-in flag so it
does not run on every boot; add a configurable check (e.g., a bool config flag
or compile-time define like enable_wave8_bench) and only invoke
runWave8ExpandBenchmark() when that flag is true (check the flag in
AutoResearch.ino before calling the function), thereby preserving current
startup behavior unless explicitly enabled.
In `@tests/fl/channels/wave8.cpp`:
- Around line 81-101: The test only checks helper-level expansion equivalence
but doesn't exercise the public overloads wave8Transpose_2/4/8/16 that accept a
const Wave8ByteExpansionLut&, so add test coverage that calls each public
transpose overload with the byteLut you already build (Wave8ByteExpansionLut
byteLut = buildWave8ByteExpansionLUT(nibble)) and validate outputs against the
nibble-based path; for each b in 0..255, produce the expected transposed output
by using the existing nibble expansion helpers
(detail::wave8_convert_byte_to_wave8byte / detail::wave8_expand_byte or the
public nibble-based transpose overloads) and then call wave8Transpose_2(...,
byteLut, ...), wave8Transpose_4(..., byteLut, ...), wave8Transpose_8(...,
byteLut, ...), wave8Transpose_16(..., byteLut, ...) comparing
returned/transposed buffers element-wise to ensure lane-order and wiring match.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c5ae5c0a-f4bc-4378-b161-8311cec306fb
📒 Files selected for processing (8)
examples/AutoResearch/AutoResearch.inoexamples/AutoResearch/AutoResearchWave8Expand.hsrc/fl/channels/detail/wave8.hppsrc/fl/channels/wave8.cpp.hppsrc/fl/channels/wave8.hsrc/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hppsrc/platforms/esp/32/drivers/parlio/parlio_engine.htests/fl/channels/wave8.cpp
…anspose16 timing Addresses review feedback on PR #2539: - Boot-time call removed by default; behind -DFL_BENCH_WAVE8_AT_BOOT=1 only. - Registers wave8ExpandBenchmark RPC handler (returns JSON via the RPC server). - Split into a pure measureWave8Expand() compute function + an optional esp_rom_printf print helper; the RPC path serializes the struct directly. - Adds full per-byte-position production timing (wave8Transpose_16 with both LUTs), not just isolated expansion — this is what the engine actually pays in the hot loop x 768 byte-positions/frame. Measured on ESP32-P4 v1.3 (boot-time bridge until #2541 routing fix): expand_only_us nibble=350142 byte=210155 batched=206528 transpose16_us nibble=530115 byte=344128 frame_equiv_us (768) expand_nibble=8963 expand_byte=5379 t16_nibble=13570 t16_byte=8809 speedup_x100 expand=166 batched=169 transpose16=154 So the **production per-byte-position hot loop is 1.54x faster** with the byte-LUT (4761 us/frame saved), and **isolated expansion is 1.66x faster**. Real encode-side measurement, not the prior 1.28x extrapolation. Follow-ups filed: #2540 (FL_PRINT vs esp_rom_printf), #2541 (testSimd RPC routing root cause). Co-Authored-By: Claude Opus 4.7 <[email protected]>
Review-driven update (latest commit
|
| metric | nibble | byte-LUT | speedup |
|---|---|---|---|
| expand-only (480k expansions) | 350,142 µs | 210,155 µs | 1.66× |
wave8Transpose_16 (prod hot path) |
530,115 µs | 344,128 µs | 1.54× |
| frame equiv (×768 byte-positions) | 13,570 µs | 8,809 µs | −4,761 µs/frame |
So the production per-byte-position cost is 1.54× faster — directly measured, not extrapolated. Full encode_us (which adds DMA/ring/ISR overhead) is bounded above by 1.54× and needs measureParlio (blocked by #2541) to nail down end-to-end.
3. Follow-ups filed
- perf(autoresearch): use FL_PRINT instead of esp_rom_printf in on-device benchmarks #2540 — switch benchmark output from
esp_rom_printftoFL_PRINTonce routing is fixed - bug(esp32p4): testSimd RPC write-timeout — Serial routes to UART0 instead of USB-Serial-JTAG #2541 — testSimd RPC routing root cause (
Serialon UART0 vs tool on USB-Serial-JTAG)
There was a problem hiding this comment.
🧹 Nitpick comments (2)
examples/AutoResearch/AutoResearch.ino (1)
334-343: 💤 Low valueConsider conventional variable naming.
The variable
_w8ruses a leading underscore, which is unconventional in C++ (though legal in local scope). Standard practice avoids leading underscores to prevent potential reserved-name conflicts.♻️ Suggested refactor
`#ifdef` FL_BENCH_WAVE8_AT_BOOT { - auto _w8r = autoresearch::wave8_bench::measureWave8Expand(); - autoresearch::wave8_bench::printWave8ExpandResultRom(_w8r); + auto w8r = autoresearch::wave8_bench::measureWave8Expand(); + autoresearch::wave8_bench::printWave8ExpandResultRom(w8r); } `#endif`🤖 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/AutoResearch.ino` around lines 334 - 343, The local variable name `_w8r` uses a leading underscore which is non-idiomatic and may risk reserved-name conflicts; rename it to a conventional local identifier (e.g., `w8r` or `wave8Result`) where it is assigned from `autoresearch::wave8_bench::measureWave8Expand()` and then passed into `autoresearch::wave8_bench::printWave8ExpandResultRom()` so both uses are updated consistently.examples/AutoResearch/AutoResearchWave8Expand.h (1)
24-29: 💤 Low valueConsider consolidating duplicate platform guards.
The same
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM)guard is used twice consecutively. Consolidating into a single block improves readability:♻️ Suggested refactor
-#if defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM) -#include <Arduino.h> // micros() -#endif -#if defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM) -#include <esp_rom_sys.h> // esp_rom_printf -> USB-Serial-JTAG console (`#2540`) -#endif +#if defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM) +#include <Arduino.h> // micros() +#include <esp_rom_sys.h> // esp_rom_printf -> USB-Serial-JTAG console (`#2540`) +#endif🤖 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/AutoResearchWave8Expand.h` around lines 24 - 29, Two consecutive platform guards repeat the same condition; consolidate them by merging both includes into a single `#if` defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM) block so both <Arduino.h> and <esp_rom_sys.h> are included together. Locate the duplicate guards around the includes for Arduino.h and esp_rom_sys.h in AutoResearchWave8Expand.h and move both `#include` lines inside one combined preprocessor conditional (keeping the original macros ARDUINO_ARCH_ESP32 and ESP_PLATFORM and preserving the comment about esp_rom_printf).
🤖 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/AutoResearch.ino`:
- Around line 334-343: The local variable name `_w8r` uses a leading underscore
which is non-idiomatic and may risk reserved-name conflicts; rename it to a
conventional local identifier (e.g., `w8r` or `wave8Result`) where it is
assigned from `autoresearch::wave8_bench::measureWave8Expand()` and then passed
into `autoresearch::wave8_bench::printWave8ExpandResultRom()` so both uses are
updated consistently.
In `@examples/AutoResearch/AutoResearchWave8Expand.h`:
- Around line 24-29: Two consecutive platform guards repeat the same condition;
consolidate them by merging both includes into a single `#if`
defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM) block so both <Arduino.h>
and <esp_rom_sys.h> are included together. Locate the duplicate guards around
the includes for Arduino.h and esp_rom_sys.h in AutoResearchWave8Expand.h and
move both `#include` lines inside one combined preprocessor conditional (keeping
the original macros ARDUINO_ARCH_ESP32 and ESP_PLATFORM and preserving the
comment about esp_rom_printf).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6d846260-5ec8-45f4-979b-c319556ab418
📒 Files selected for processing (3)
examples/AutoResearch/AutoResearch.inoexamples/AutoResearch/AutoResearchRemote.cppexamples/AutoResearch/AutoResearchWave8Expand.h
…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]>
…AT_BOOT (#2618) Stop running the 85-test SIMD validation suite unconditionally on every boot of the AutoResearch example. The testSimd RPC handler in AutoResearchRemote.cpp is the canonical invocation path; the boot-time call was a redundant ~50-100 ms tax plus log noise for anyone using AutoResearch as the regular LED autoresearch tool. Mirrors the FL_BENCH_WAVE8_AT_BOOT / FL_BENCH_PARLIO_AT_BOOT pattern from PR #2539: keep the function callable, gate the boot-time invocation behind an opt-in macro for use as a bridge until the testSimd RPC routing on P4 is fixed (#2541). Closes #2542 Co-authored-by: Claude Opus 4.7 <[email protected]>
Summary
Implements the byte-indexed expansion LUT proposed in #2526 — the "wider lookups, fewer stores" strategy from the deep-dive comment. Replaces the two nibble lookups in the hot PARLIO encode path with a single indexed 8-byte copy, same bit-exact output, ~half the per-byte index work.
Why this works
Expansion runs 16 lanes × 768 byte-positions = 12,288×/frame and was dominated by index arithmetic + issue width on the in-order RV32 core, not memory bandwidth. Cutting the per-byte instruction count from ~11 to ~6 (no
>>4/mask, no second index, single 8-byte load/store pair) is the right shape for that bottleneck — same independent-ops lesson that made the spread-LUT transpose win on this core.Changes
Wave8ByteExpansionLut(256×8 = 2 KB) +buildWave8ByteExpansionLUT(nibble)builder.detail::wave8_expand_byte()— single indexed 8-byte copy,FORCE_INLINE FL_IRAM.wave8Transpose_{2,4,8,16}; PARLIO engine holdsmWave8ByteLutalongsidemWave8Lutand routes all 5 hot expansion call sites through it (single-lane + 2/4/8/16-lane multi-lane).buildWave8ByteExpansionLUT_matches_nibble_pathchecks all 256 input bytes are bit-identical to the nibble path.AutoResearchWave8Expand.h) prints viaesp_rom_printf→ USB-Serial-JTAG console so results are capturable on COM25 without the broken testSimd RPC (see feat(esp32-p4): add PIE (xesppie) SIMD backend to fl::simd #2536/feat(esp32-p4): PIE (xesppie) SIMD backend Tier-1 ops (#2536) #2538).Measured on real ESP32-P4 (revision v1.3)
At expansion ~55% of encode, this predicts ~1.28× full encode_us — matching the prediction posted on #2526.
Test plan
bash test wave8 --cpp(all wave8 tests including new equivalence test pass)bash test parlio_driver --cpp(parlio path still passes)bash lint --cppclean (incl. the strict NativePlatformDefinesChecker / UsingNamespaceFlInExamplesChecker)bash autoresearch esp32p4 --simd --no-fbuild)Refs #2526, #2524 (umbrella), #2533 (spread-LUT transpose precedent), #2538 (P4 PIE backend / serial-routing context for the bench output workaround)
Summary by CodeRabbit
New Features
Refactor
Tests