Skip to content

fix(wave): switch WaveSimulation2D_Real grids from vector_psram to SRAM (closes #3114) - #3117

Merged
zackees merged 1 commit into
masterfrom
fix/3114-vector-psram-default
Jun 16, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3114-vector-psram-default

Conversation

@zackees

@zackees zackees commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Closes #3114. Switches the silent vector_psram<i16> grid default in WaveSimulation2D_Real to plain fl::vector<i16> (SRAM).

Why

The previous default landed both wave grids in PSRAM on every ESP32 with PSRAM available. On ESP32-S3 (no L2 cache) this paid the full ~80 ns PSRAM access latency per cell — the 5-point stencil reads 5 cells per inner cell, so a 64×64 update was reading ~80 KB per step at ~50 MB/s practical PSRAM throughput → ~1.6 ms per step on memory alone, cratering frame rate at the grid sizes users actually want.

Worse, identical-looking user code produced wildly different frame rates on ESP32-S3 vs Teensy 4 vs ESP32-P4 depending on whether each had PSRAM. The auto-decision is the actual bug; making storage choice predictable is the fix.

Where the grids now live

Platform Internal SRAM Max grid (i16, 2 buffers + halo)
AVR 2 KB tiny — was always SRAM here
Cortex-M0 / RP2040 264 KB 128×128 comfortably
Teensy 4 (OCRAM) 512+ KB 256×256
ESP32-S3 320 KB 128×128 easily, 256×256 tight
ESP32-P4 ~750 KB 256×256 + headroom

Users who genuinely need grids bigger than SRAM allows can construct a parallel WaveSimulation2D_Real_Large (deferred follow-up) that re-enables PSRAM as an explicit, documented opt-in.

Validation

  • bash test fl_math_wave_wave_simulation_real --cpp — 8/8 pass.
  • bash lint --cpp — clean.

Out of scope

Closes #3114
Refs #3113 (parent meta — Wave2D perf pipeline)

Summary by CodeRabbit

  • Performance
    • Internal optimization to wave simulation memory management for improved efficiency.

The previous fl::vector_psram<i16> default silently put both wave grids
in PSRAM on every ESP32 with PSRAM available — including ESP32-S3,
which has no L2 cache. The 5-point stencil reads 5 cells per inner
cell, so a 64x64 update was reading ~80 KB per step at ~50 MB/s
practical PSRAM throughput → ~1.6 ms per step on memory alone.
Identical-looking user code produced wildly different frame rates on
ESP32-S3 vs Teensy 4 vs ESP32-P4.

Switch to fl::vector<i16> (SRAM). Predictable everywhere:
- ESP32-S3: 320 KB SRAM, 64x64 i16 grid = 8 KB, 128x128 = 32 KB,
  both fit easily.
- ESP32-P4: ~750 KB SRAM, 256x256 fits.
- Teensy 4: OCRAM, even faster.
- AVR / Cortex-M0: grid sizes were already SRAM-only via the 1D class
  precedent; this aligns 2D with that pattern.

Header comment documents the rationale + points at #3114 for the
follow-up PSRAM opt-in (WaveSimulation2D_Real_Large) for users who
genuinely need grids bigger than SRAM can hold.

Closes #3114
Refs #3113 (parent meta — Wave2D perf pipeline)
@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 85f544ad-3ed7-49e8-b128-91cd73a6ec07

📥 Commits

Reviewing files that changed from the base of the PR and between 8d19776 and 3591d8e.

📒 Files selected for processing (1)
  • src/fl/math/wave/wave_simulation_real.h

📝 Walkthrough

Walkthrough

In WaveSimulation2D_Real, the two private simulation buffers grid1 and grid2 are retyped from fl::vector_psram<i16> to fl::vector<i16>, making SRAM the default storage. A multi-line comment is added explaining the rationale and expected latency impact. No public API or method signatures are changed.

Changes

PSRAM → SRAM buffer switch in WaveSimulation2D_Real

Layer / File(s) Summary
Retype grid1/grid2 to SRAM-backed vectors
src/fl/math/wave/wave_simulation_real.h
grid1 and grid2 private members changed from fl::vector_psram<i16> to fl::vector<i16>, with a new comment block documenting the SRAM-default rationale and PSRAM latency implications.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 Two grids once lived in PSRAM's slow lane,
Eighty nanoseconds paid, again and again.
A hop to SRAM, swift as a spring breeze —
No more frame-rate cliffs to make devs freeze.
Now waves ripple fast, the bunny is pleased! 🌊

✨ 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 fix/3114-vector-psram-default

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.

@zackees
zackees merged commit 7e17f58 into master Jun 16, 2026
7 of 8 checks passed
@zackees
zackees deleted the fix/3114-vector-psram-default branch June 16, 2026 01:21
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 16, 2026
zackees added a commit that referenced this pull request Jun 16, 2026
…1 / #3113 Task 1) (#3134)

A1 of meta #3122. Wires the device-side wave2dPerf (#3116) + perfProbe*
(#3118) RPCs (refactored behind fl::wave_perf::* in #3120) into a
single host-driven measurement pass.

  bash autoresearch esp32s3 --wave2d-perf 64x64

Sequence per platform run:
  1. perfProbeMemcpy — SRAM throughput, MB/s.
  2. perfProbeNop    — cycle calibration, us/iter.
  3. perfProbeRepeat — wave2dPerf reproducibility, std_dev_pct.
                       >= 5% stamps results UNTRUSTED.
  4. wave2dPerf x 4 — { FivePoint, NinePointIsotropic } x
                       { compute, loads_only }.
                      The loads_only/compute gap isolates memory
                      cost from compute cost (critical for ESP32-S3
                      per #3114 / #3117 PSRAM analysis).

Output: per-RPC live progress + final JSON dump with structured
results { grid, probes, bench, untrusted, untrusted_reasons }.

Naming note: per #3124, future perf-related flags use the
--perf-XX prefix convention. This flag uses the original
--wave2d-perf name per explicit user direction in this session
("don't fix this now, just file an issue") — #3124 tracks the
prefix-rename pass for a future PR.

Args dataclass + RunContext extended with the new field; existing
test fixture updated to construct both with the new defaults. All
48 ci/tests/test_autoresearch_phases.py tests pass.

Refs #3122 A1, #3113 Task 1.
zackees added a commit that referenced this pull request Jun 16, 2026
…efs #3122 A3) (#3141)

A3 of meta #3122. Closes the deferred PSRAM opt-in follow-up from #3114
without introducing a parallel class — instead, exposes a tag-dispatch
constructor overload on the existing WaveSimulation2D_Real:

  WaveSimulation2D_Real sim{
      WaveSimulation2D_Real::PsramStorage{}, 256, 256};

Default constructor stays SRAM (post-#3117 default). PsramStorage tag
explicitly opts a grid into PSRAM for users who genuinely need a grid
larger than SRAM can hold AND accept the per-cell perf cost (~5-10x
slower on ESP32-S3 without L2 cache; ~no cost on ESP32-P4 with L2 +
cached PSRAM).

Implementation:
- New PsramStorage tag type on WaveSimulation2D_Real.
- New tag-dispatch constructor that constructs grid1/grid2 with
  psram_memory_resource() instead of the default SRAM resource.
- Cell count populated via resize() after PSRAM allocation.

Avoided creating a parallel WaveSimulation2D_Real_Large class — the
duplicated body would have been a maintenance burden, and the existing
class is already SRAM by default after #3117. One class, two
constructors, predictable storage.

Verified by tests/fl/math/wave/wave_simulation_real.cpp (9/9 cases
pass, including the new PSRAM constructor exercise). The PSRAM
constructor falls back to default allocator on host where there's no
real PSRAM, so the test exercises the constructor path everywhere.

Refs #3122 A3, #3114 (now closed), #3117 (SRAM default), #3113 parent
meta.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(wave): remove silent vector_psram default in WaveSimulation2D_Real — SRAM by default, PSRAM opt-in

1 participant