Repository navigation
Description
Background
The audit family #3073 / closed meta #3098 produced an optimized scalar WaveSimulation2D_Real kernel (PRs #3083, #3099, #3101, #3103, #3104, #3105, #3110). The research doc landed in PR #3112 (agents/docs/research/wave_pde_alternatives.md) identified 5 algorithmic follow-ups that should beat SIMD on the cost/quality axis.
Everything past this point is bottlenecked on measurement. Optimizing further without a trustworthy per-platform performance benchmark means we'd be picking algorithms based on theory rather than against-hardware data — exactly the failure mode the research doc warns about for SIMD work.
This meta tracks getting that benchmark in place, capturing baselines, and then sequencing the algorithmic follow-ups against measured wins.
PSRAM concern that motivated this meta
The current WaveSimulation2D_Real stores its two i16 grids in fl::vector_psram<i16>, which on ESP32-S3 means PSRAM-backed storage. That's a design decision that needs validation:
| Platform | Cache | PSRAM throughput (practical) | Notes |
|---|---|---|---|
| ESP32-S3 | no L2 | ~50–80 MB/s (octal SPI PSRAM) | Per-access penalty ~80 ns. No prefetcher to mask. |
| ESP32-P4 | L2 + RVV | ~500+ MB/s (HEX-mode PSRAM) | Cache hides the latency for stencil-pattern access. |
| ESP32-C6 | SRAM only | n/a | RISC-V single-core @ 160 MHz; no PSRAM in typical configs. |
| Teensy 4.0 / 4.1 | Cortex-M7 L1 | DTCM/OCRAM (fast); FlexSPI PSRAM is slow | Internal RAM is the right home for the grid. |
Concrete back-of-envelope on ESP32-S3: 100×100 i16 grid = 20 KB. The 5-point stencil update reads ~5 cells per inner cell per step ≈ 100 KB per step. At 50 MB/s practical PSRAM throughput that's ~2 ms per step on load alone, before any compute. At 30 fps that's 6% of the CPU just on grid loads — and that's before the kernel does any arithmetic. On ESP32-P4 the same workload would be ~10× faster because L2 catches the cells the next iteration needs.
The hypothesis to test: vector_psram<i16> is the wrong default on ESP32-S3 for grids that fit in SRAM. A 64×64 grid is 8 KB and fits trivially in S3's 320 KB SRAM. The perf benchmark below has to actually demonstrate the SRAM-vs-PSRAM gap before we change the default.
Platform targets
Grid sizes we expect to run smoothly at 30 fps:
| Platform class | Target grid | Storage path | Why |
|---|---|---|---|
| AVR (Uno / ATmega328) | 8×8 | SRAM | RAM budget |
| Cortex-M0 (RP2040, Teensy-LC) | 16×16 | SRAM | No FPU, software multiply for some ops |
| ESP32-C6 | 32×32 | SRAM | RISC-V @ 160 MHz, no PSRAM in stock config |
| ESP32 (original) | 32×32 | SRAM | Dual Tensilica @ 240 MHz |
| ESP32-S3 | 64×64 | SRAM (PSRAM optional, opt-in) | DSP coproc + PIE SIMD, but PSRAM is slow |
| Teensy 4.0 / 4.1 | 64×64 (headroom to 128×128) | DTCM/OCRAM | Cortex-M7 @ 600 MHz, fast internal RAM |
| ESP32-P4 | 64×64 (headroom to 128×128) | L2-cacheable, PSRAM OK | RVV SIMD, L2 cache, fast PSRAM |
The bold rows are the ones the user named explicitly. The non-bold rows are the platforms we already test against and need to keep working.
Sub-tasks tracked by this meta
1. Wave2D autoresearch performance benchmark — DESIGN
Goal: a repeatable, deterministic, sub-millisecond-resolution perf test for WaveSimulation2D_Real::update() that runs through the existing autoresearch RPC infrastructure on real hardware. Without this, every other item in this meta is theory.
Approach:
- No new
.ino— extendexamples/AutoResearch/AutoResearch.inoperCLAUDE.mdpolicy. Add awave2d_perfRPC handler. - Invocation from the host side:
bash autoresearch <board> --wave2d-perf <W>x<H>(new--wave2d-perfflag inci/autoresearch.py). - The RPC handler takes
(W, H, stencil_id, iterations, storage_mode)and returns a timing dict. - Storage mode is one of
SRAM/PSRAM/default— lets us A/B the same grid in two locations on ESP32-S3.
Measurement contract:
result = {
"platform": "esp32s3",
"grid": [64, 64],
"stencil": "NinePointIsotropic",
"storage": "SRAM",
"iterations": 1000,
"total_cycles": 12345678,
"cycles_per_update": 12345.678,
"cycles_per_cell_per_update": 3.014,
"loads_only_cycles_per_cell": 1.823, # baseline: just sum the grid
"wall_clock_us_per_update": 51.4,
"fps_at_one_update_per_frame": 19450,
"std_dev_pct": 1.2,
}Timing primitives:
- ESP32:
esp_cpu_get_cycle_count(). - Cortex-M:
ARM_DWT_CYCCNT(DWT cycle counter, enable once at boot). - AVR: 16-bit Timer1 prescaler 1 (1-cycle resolution but 65 K-cycle range — split long runs).
- Host:
std::chrono::steady_clock.
Two separate measurements per run, isolation matters:
loads_onlybaseline. A helper that reads the same 5-cell stencil pattern but only sums the values, no multiply / damp / clamp. Lets us separate the memory-bound floor from the compute addition. On ESP32-S3 PSRAM-backed, the gap betweenloads_onlyandupdatewill be small (memory dominates). On L2-cached platforms the gap will be large (compute dominates).updatefull kernel. What we actually care about.
Grid sizes per platform:
Run at 16×16, 32×32, and 64×64 wherever each fits in RAM. The scaling curve tells us when we hit cache / PSRAM thresholds.
Stencil sweep:
Run all currently-implemented stencils — FivePoint, NinePointIsotropic — plus any new ones as they ship (compact-O(h⁴) is the obvious next addition per #3112).
Output:
Python-side reporter formats one comparison table per platform. Cross-platform comparison table at the end.
2. Autoresearch perf-measurement sanity / calibration test
Goal: before we use autoresearch perf numbers to gate optimization decisions, prove autoresearch's timing infrastructure produces trustworthy data on each platform.
Three quick sanity probes:
2a. Known-throughput memcpy microbench
void rpc_memcpy_throughput(uint32_t bytes, uint32_t iterations) {
static uint8_t src[8192]; // in SRAM
static uint8_t dst[8192];
uint32_t t0 = cycle_count();
for (uint32_t i = 0; i < iterations; ++i) {
memcpy(dst, src, bytes);
}
uint32_t t1 = cycle_count();
// Return measured MB/s.
}Pass criterion: measured MB/s within 30% of vendor spec for SRAM bandwidth.
| Platform | Vendor MB/s (SRAM) | Min acceptable |
|---|---|---|
| ESP32-S3 | ~250 | 175 |
| ESP32-C6 | ~200 | 140 |
| Teensy 4.0 OCRAM | ~600 | 420 |
| AVR | ~5 | 3.5 |
If measured throughput is <50% of vendor spec → autoresearch timing instrumentation is broken; bail loudly.
2b. Idle-loop calibration
void rpc_nop_calibration(uint32_t iterations) {
uint32_t t0 = cycle_count();
for (uint32_t i = 0; i < iterations; ++i) {
__asm__ volatile ("nop");
}
uint32_t t1 = cycle_count();
// Expected: ~iterations cycles + small constant.
}Pass criterion: (t1 - t0) / iterations ∈ [1.0, 2.5] cycles/nop. >2.5 means there's overhead (IRQ jitter, branch predictor stalls, RPC framing leak); <1.0 means the cycle counter is broken (probably running at a different clock domain).
2c. Repeat-stability check
Run the full wave2d_perf test 10 times back-to-back at fixed (W, H, stencil). Report mean and std dev. Pass criterion: std dev < 5% of mean. Higher → IRQ noise, RPC contention, or autoresearch reporter rounding.
Fail-loud contract:
If ANY of 2a / 2b / 2c fails on a platform, the autoresearch reporter MUST stamp the result with AUTORESEARCH_PERF_UNTRUSTED=true and refuse to feed it into the cross-platform comparison table. Silent corruption of perf data is worse than no data.
3. SIMD backlog (already filed, on hold)
- feat(wave): host SIMD backend for 2D wave PDE update kernel — SSE2/AVX2/NEON (split from #3097) #3106 — host SIMD (SSE2/AVX2/NEON)
- feat(wave): ESP32-S3 PIE SIMD backend for 2D wave PDE update kernel (split from #3097) #3107 — ESP32-S3 PIE SIMD
- feat(wave): Teensy 4 DSP-intrinsic SIMD backend for 2D wave PDE update kernel (split from #3097) #3108 — Teensy 4 DSP-intrinsic SIMD
Remain on hold pending:
- Task 1 (perf benchmark) merged.
- Task 4 algorithmic candidates evaluated against perf benchmark.
Rationale: per the #3112 research doc, the algorithmic wins (compact-4 stencil, screen-space blur replacing SS, procedural waves) each beat SIMD's typical 4–8×. Pick the algorithm before tuning the constant factor.
4. Algorithmic follow-ups from #3112 research doc
To be filed as separate sub-issues once Task 1's perf benchmark is in place and baselines are captured:
- Compact O(h⁴) 9-point Laplacian — third option on the existing
LaplacianStencilenum. Same memory pattern as the isotropic 9-point from feat(wave): opt-in 9-point isotropic Laplacian for WaveSimulation2D (closes #3095) #3104, O(h⁴) accuracy. Probably ship first since the diff is smallest. - Output Gaussian blur as super-sample replacement — addresses super-sample's actual user motivation (LED-grid AA) at ~1.2× scalar cost vs 8–512× for SS 2X/4X/8X.
-
WaveProceduralFx— sum-of-Gerstner-wavelets — bypasses the PDE entirely. Zero grid memory. AVR / Low-memory win. - Tile-level active-region tracking — extends existing
useChangeGridinfrastructure. Biggest win on ESP32-S3 with PSRAM-backed large grids (skip the PSRAM read entirely for idle tiles). - Q7/Q8 grid storage option — templated
Storage = i16 | i8. Halves PSRAM bandwidth on ESP32-S3.
Each candidate's PR must report perf-benchmark numbers from Task 1 on at least ESP32-S3, ESP32-C6, Teensy 4.0, and host. Without those numbers the PR cannot be evaluated against the alternatives.
5. PSRAM storage — vector_psram<i16> default is wrong (tracked separately)
The current WaveSimulation2D_Real declares its two grids as fl::vector_psram<i16>, which silently lands them in PSRAM on any ESP32 that has it. This is the wrong default:
- ESP32-S3 has no L2 cache. Every cell access pays full PSRAM latency (~80 ns). The 5-point stencil's interior loop touches 5 cells per inner cell, so a 64×64 update reads ~80 KB per step. At ~50 MB/s PSRAM throughput that's ~1.6 ms per step on memory alone, before any compute — borderline at 30 fps and ruins frame rate at the grid sizes users actually want.
- ESP32-P4 has L2 cache (128 KB), which helps for grids that fit in L2. A 64×64 i16 grid is 8 KB and lives in L2 fine. A 128×128 grid is 32 KB and also fits. But the moment a user goes to 256×256 (128 KB grid + halo) the working set blows L2 and we're back to streaming PSRAM. So even on P4, "PSRAM is always fine" doesn't hold.
- Auto-decision by the wrapper is dangerous. A grid size that's safe on P4 ruins frame rate on S3, and silently changing storage based on
__has_psram()produces wildly different perf on hardware that looks identical to the user.
Fix tracked in its own focused follow-up issue (file alongside this meta). Design space for the fix:
| Option | Mechanism | Pros | Cons |
|---|---|---|---|
| A. SRAM by default, explicit PSRAM opt-in | Switch WaveSimulation2D_Real grids to fl::vector<i16>; add a WaveSimulation2D_Real_Large variant (or templated Allocator) that uses PSRAM |
Predictable perf, simple mental model | User has to know they're opting in |
B. Templated Storage/Allocator parameter |
WaveSimulation2D_Real<Alloc>; wrapper class picks based on size |
Most flexible | Doubles template instantiations; harder to debug perf |
| C. Size-gated default in wrapper | WaveSimulation2D picks SRAM for W*H ≤ 64×64, PSRAM otherwise |
Hides decision from user | Same hidden-perf-cliff problem as today, just at a different size |
Default recommendation (subject to perf data from Task 1): Option A. Public API stays simple; PSRAM becomes an explicit, documented choice for users who genuinely have large grids and accept the perf cost.
This is large enough to belong in its own focused issue, not a checkbox here. Status: filed as #3114.
Acceptance criteria for closing this meta
- Task 1 (perf benchmark) merged. RPC handler in AutoResearch, host-side
--wave2d-perf <W>x<H>flag, JSON reporter. - Task 2 (sanity calibration) merged. All three probes (memcpy, nop, repeat-stability) running and gating output.
- Baselines captured and committed (e.g.
agents/docs/research/wave2d_perf_baselines_2026q2.md) for:- ESP32-S3 — both SRAM and PSRAM storage paths
- ESP32-C6
- Teensy 4.0 (or 4.1 as proxy)
- ESP32-P4 (when available)
- Host (reference)
- PSRAM storage follow-up fix(wave): remove silent vector_psram default in WaveSimulation2D_Real — SRAM by default, PSRAM opt-in #3114 (Task 5) MERGED, with
vector_psramno longer the silent default on ESP32-S3. - At least 2 of the 5 algorithmic follow-ups in Task 4 implemented, with their PRs containing perf-benchmark numbers.
- Compact O(h⁴) Laplacian (the smallest-diff biggest-win) is one of those 2.
- Decision on each of feat(wave): host SIMD backend for 2D wave PDE update kernel — SSE2/AVX2/NEON (split from #3097) #3106 / feat(wave): ESP32-S3 PIE SIMD backend for 2D wave PDE update kernel (split from #3097) #3107 / feat(wave): Teensy 4 DSP-intrinsic SIMD backend for 2D wave PDE update kernel (split from #3097) #3108: implement, drop, or keep on hold with stated reason. (Likely: drop or hold permanently — the algorithmic wins should make SIMD unnecessary for the target frame budgets.)
Stop condition
This meta closes when the acceptance criteria above all hold OR when the user explicitly decides to defer remaining items. The 5 algorithmic follow-ups don't all have to land here — the meta can close after the perf infrastructure is in place and the top 2 candidates are validated.
Cross-references
- Audit family that produced the current scalar kernel: audit(wave/diff-eq): overflow risk + perf wins in WaveSimulation Q15 stencil (behind WaveFx) #3073 (closed), [meta] WaveSimulation Q15 stencil — perf + algorithmic follow-ups from #3073 #3098 (closed)
- Research doc that motivated this meta: research(wave): state-of-the-art survey for 2D wave PDE alternatives (closes #3111) #3112 (merged) →
agents/docs/research/wave_pde_alternatives.md - Active SIMD sub-issues on hold: feat(wave): host SIMD backend for 2D wave PDE update kernel — SSE2/AVX2/NEON (split from #3097) #3106, feat(wave): ESP32-S3 PIE SIMD backend for 2D wave PDE update kernel (split from #3097) #3107, feat(wave): Teensy 4 DSP-intrinsic SIMD backend for 2D wave PDE update kernel (split from #3097) #3108
- Earlier related issue work: fix(wave): prevent i32 overflow in Q15 Courant*Laplacian multiply (refs #3073) #3083, perf(wave): replace damping division by arithmetic shift (closes #3092) #3099, perf(wave): fold half-duplex zero-clamp into main update loop (closes #3093) #3101, perf(wave): hoist row arithmetic + FL_RESTRICT_PARAM in 2D update inner loop (closes #3094) #3103, feat(wave): opt-in 9-point isotropic Laplacian for WaveSimulation2D (closes #3095) #3104, perf(wave): precompute damping decay as a Q15 multiplier (closes #3096) #3105, feat(wave): expose 9-point isotropic Laplacian as a UI toggle in Wave2d/FxWave2d/Downscale/XYPath/FestivalStick sketches #3109, feat(wave): expose 9-point isotropic Laplacian as UI toggle in 5 example sketches (closes #3109) #3110, research: state-of-the-art alternatives to super-sample for visual quality in 2D wave PDE (Wave2d / WaveFx) — define research bot + search catalog #3111
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriage
Activity
feat(autoresearch): add wave2dPerf RPC handler — Task 1 of meta #3113 (…
fix(wave): switch WaveSimulation2D_Real grids from vector_psram to SR…
feat(autoresearch): add perfProbe sanity probes — Task 2 of meta #3113 (
refactor(wave): move perf-bench logic into wave simulator; AutoResear…
feat(autoresearch): add --wave2d-perf <W>x<H> host flag (refs #3122 A…
feat(wave): explicit PsramStorage opt-in for WaveSimulation2D_Real (r…
feat(wave): output Gaussian-style blur as super-sample alternative (r…
BitsForPeople commentedon Jul 6, 2026
Notice that on the ESP32-S3, PSRAM does operate via the cache.
zackees commentedon Jul 6, 2026
Thanks i didnt know that. This may change the calculus. I'll have to test it to see what the hit is.
zackees commentedon Aug 20, 2026
Burn-down disposition: DEFER ? this is a multi-platform performance program with remaining hardware and algorithm-selection work, not one bounded PR.
Acceptance audit on current
master:--perf-wave2dorchestration (feat(autoresearch): --wave2d-perf <W>x<H> host flag (refs #3122 A1 / #3113 Task 1) #3134, renamed--perf-wave2dby chore(autoresearch): use --perf-XX / --test-XX flag prefixes (#3124) #3742), SRAM default (fix(wave): switch WaveSimulation2D_Real grids from vector_psram to SRAM (closes #3114) #3117), explicit PSRAM opt-in (feat(wave): explicit PsramStorage opt-in for WaveSimulation2D_Real (refs #3122 A3) #3141), and output blur (feat(wave): output Gaussian-style blur as super-sample alternative (refs #3122 A4) #3145).agents/docs/research/for ESP32-S3, C6, Teensy 4, P4, and host; the only Wave2D research artifact is the alternatives survey.WaveProceduralFx, active-region tracking, and Q7/Q8 storage are not implemented.Restart criteria:
--perf-wave2dat 16?16/32?32/64?64, commit raw JSON and a versioned baseline report for all required platforms/storage modes.The already-merged plumbing is valuable, but it does not satisfy the meta's own stop condition.