Skip to content

feat(wave): explicit PsramStorage opt-in for WaveSimulation2D_Real (refs #3122 A3) - #3141

Merged
zackees merged 1 commit into
masterfrom
feat/3122-a3-psram-large-variant
Jun 16, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3122-a3-psram-large-variant

Conversation

@zackees

@zackees zackees commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

A3 of meta #3122. Closes the deferred PSRAM opt-in follow-up from #3114 without introducing a parallel class.

API

Tag-dispatch constructor overload:

// Default — SRAM (post-#3117).
WaveSimulation2D_Real sim{64, 64};

// Explicit PSRAM opt-in (#3122 A3).
WaveSimulation2D_Real sim_large{
    WaveSimulation2D_Real::PsramStorage{}, 256, 256};

Why this approach

Considered and rejected: a parallel WaveSimulation2D_Real_Large class. The body would have duplicated everything; the existing class is already SRAM by default. One class, two constructors, predictable storage.

When to use PsramStorage{}

Users who genuinely need a grid larger than SRAM can hold AND accept the per-cell perf cost:

  • ESP32-S3 (no L2): ~5-10× slower per cell vs SRAM.
  • ESP32-P4 (L2 + cached PSRAM): ~no measurable cost.
  • Teensy 4 (OCRAM is already fast): no benefit.

Validation

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

The new test case (WaveSimulation2D_Real PSRAM opt-in constructor builds and runs) exercises the constructor path on host where psram_memory_resource() falls back to the default allocator.

Refs #3122 A3, #3114 (closed), #3117 (SRAM default), #3113 parent meta.

Summary by CodeRabbit

  • New Features

    • Wave simulation now supports an opt-in memory storage configuration option, enabling developers to select alternative allocation strategies for simulation grids based on application requirements.
  • Tests

    • Added test coverage for the new storage option, validating proper initialization and correct simulation behavior.

…efs #3122 A3)

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.
@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: 9aa31397-3e17-416b-bd87-3880d523278d

📥 Commits

Reviewing files that changed from the base of the PR and between 2df75a6 and b15979d.

📒 Files selected for processing (3)
  • src/fl/math/wave/wave_simulation_real.cpp.hpp
  • src/fl/math/wave/wave_simulation_real.h
  • tests/fl/math/wave/wave_simulation_real.cpp

📝 Walkthrough

Walkthrough

Adds a PSRAM opt-in constructor to WaveSimulation2D_Real via a new PsramStorage tag type. The constructor allocates grid1 and grid2 using psram_memory_resource() and resizes them to the padded (W+2)*(H+2) dimensions. A regression test exercises the new path.

Changes

PSRAM opt-in constructor for WaveSimulation2D_Real

Layer / File(s) Summary
PsramStorage tag type and constructor declaration
src/fl/math/wave/wave_simulation_real.h
Defines the nested PsramStorage tag struct and declares the constructor overload accepting it with W, H, speed, and dampening parameters (defaults 0.16f and 6.0f).
PSRAM-backed constructor implementation
src/fl/math/wave/wave_simulation_real.cpp.hpp
Implements the tagged constructor: initializes grid1 and grid2 with psram_memory_resource() and resizes both to (W+2)*(H+2); existing constructor and simulation methods are untouched.
Regression test
tests/fl/math/wave/wave_simulation_real.cpp
Adds an FL_TEST_CASE that builds via PsramStorage{}, applies a single impulse update, and asserts all outputs are within [-32768, 32767] with at least one nonzero cell.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3117: Modifies the same grid1/grid2 storage in WaveSimulation2D_Real, switching from vector_psram to vector (SRAM default), which is the complementary change that this PR builds on for the explicit PSRAM opt-in path.

Poem

🐇 Hop, hop, into the RAM we go,
PSRAM tag says: "Allocate below!"
grid1 and grid2 stretch wide and tall,
Impulse sent — no cell shall fall.
Tests confirm each wave stays true,
Explicit opt-in, through and through! ✨

✨ 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 feat/3122-a3-psram-large-variant

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 67107ce into master Jun 16, 2026
6 of 8 checks passed
@zackees
zackees deleted the feat/3122-a3-psram-large-variant branch June 16, 2026 03:01
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 16, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 16, 2026
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.

1 participant