Skip to content

refactor(wave): perf-bench owned by wave simulator; AutoResearch is external binder (refs #3113) - #3120

Merged
zackees merged 1 commit into
masterfrom
refactor/wave-perf-bench-external
Jun 16, 2026
Merged

zackees merged 1 commit into
masterfrom
refactor/wave-perf-bench-external

Conversation

@zackees

@zackees zackees commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Per user feedback on PRs #3116 + #3118: wave-PDE benchmarking belongs to the wave simulator side, not to the AutoResearch RPC layer. AutoResearchRemote.cpp was embedding wave PDE setup (checkerboard seed, halfDuplex off, stencil selection, warm-up, timing, statistics) inline in two RPC lambdas — the RPC layer should not know wave-PDE-specific details that don't belong in transport plumbing.

Separation of concerns

New, simulator-side: src/fl/math/wave/wave_perf_bench.h

namespace fl::wave_perf {
  struct WavePerfResult { /* total_us, us_per_update, ... */ };
  struct WavePerfRepeatResult { /* mean, std_dev, std_dev_pct, ... */ };
  WavePerfResult runWavePerf(W, H, iterations, stencil);
  WavePerfResult runWavePerfLoadsOnly(W, H, iterations, stencil);
  WavePerfRepeatResult runWavePerfRepeat(W, H, iterations, repeats, stencil);
}

Existing, binder-side: examples/AutoResearch/AutoResearchRemote.cpp — wave2dPerf and perfProbeRepeat RPC handlers become thin JSON-RPC translators: parse args, dispatch to fl::wave_perf::*, format response.

Why header-only

Bench helpers are co-located with the simulator they measure, compile-time-cheap, and reusable by any future RPC layer (BLE, HTTP, etc.) or driven directly from a unit test without standing up the AutoResearch sketch.

What's deliberately unchanged

Validation

  • bash test fl_math_wave_wave_simulation_real --cpp — 8/8 pass.
  • bash lint --cpp — clean.
  • bash compile wasm --examples AutoResearch — build clean.

Refs #3113 Task 1 + Task 2.

Summary by CodeRabbit

  • Refactor
    • Reorganized wave simulation performance benchmarking infrastructure into a dedicated module for improved maintainability and reusability.
    • Updated the AutoResearch example to utilize the new benchmarking implementation, streamlining performance measurement for RPC calls.

…ch becomes external binder

Per user direction: wave-PDE benchmarking belongs to the wave simulator,
not to the AutoResearch RPC layer. AutoResearchRemote.cpp was embedding
the wave PDE setup (checkerboard seed, halfDuplex off, stencil selection,
warm-up, timing, statistics) inline in two RPC lambdas (wave2dPerf,
perfProbeRepeat). The simulator side did not own its own bench API; the
RPC layer had to know wave-PDE-specific details that don't belong in
transport plumbing.

This PR cleanly separates concerns:

  src/fl/math/wave/wave_perf_bench.h (new):
    namespace fl::wave_perf:
      struct WavePerfResult, WavePerfRepeatResult
      runWavePerf(W, H, iterations, stencil) -> WavePerfResult
      runWavePerfLoadsOnly(W, H, iterations, stencil) -> WavePerfResult
      runWavePerfRepeat(W, H, iterations, repeats, stencil) -> WavePerfRepeatResult

  examples/AutoResearch/AutoResearchRemote.cpp:
    wave2dPerf and perfProbeRepeat RPC handlers become thin JSON-RPC
    binders: parse args, dispatch to fl::wave_perf::*, format response.
    No wave PDE knowledge in the RPC layer.

The header-only design keeps the bench helpers compile-time-cheap and
co-located with the simulator they measure. They can be reused by any
future RPC layer (BLE, HTTP, etc.) or driven directly from a unit test
without standing up the AutoResearch sketch.

Things deliberately unchanged:
- perfProbeMemcpy and perfProbeNop stay in AutoResearchRemote.cpp.
  They're not wave-PDE-specific; they're general SRAM/cycle-counter
  calibration helpers. If the codebase ever grows a generic
  src/fl/perf/sanity_probes.h they can move there.
- All JSON wire formats are byte-identical to #3116 (wave2dPerf) and
  #3118 (perfProbeRepeat). Existing host-side callers don't notice.

Validation:
- bash test fl_math_wave_wave_simulation_real --cpp — 8/8 pass.
- bash lint --cpp — clean.
- bash compile wasm --examples AutoResearch — build clean.

Refs #3113 Task 1 + Task 2.
@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: 84beba1c-a81e-4a14-901c-d250be3e05cf

📥 Commits

Reviewing files that changed from the base of the PR and between 4f620ff and 462b1a2.

📒 Files selected for processing (2)
  • examples/AutoResearch/AutoResearchRemote.cpp
  • src/fl/math/wave/wave_perf_bench.h

📝 Walkthrough

Walkthrough

A new header src/fl/math/wave/wave_perf_bench.h is introduced in the fl::wave_perf namespace, defining result structs, input validators, a deterministic simulator factory, and three benchmark entry points (runWavePerf, runWavePerfLoadsOnly, runWavePerfRepeat). The perfProbeRepeat and wave2dPerf RPC handlers in AutoResearchRemote.cpp are refactored to delegate to these helpers, removing ~110 lines of inline simulation/timing/statistics logic.

Changes

Wave benchmark extraction and RPC delegation

Layer / File(s) Summary
wave_perf_bench.h: structs, validation, and simulator factory
src/fl/math/wave/wave_perf_bench.h
Introduces WavePerfResult and WavePerfRepeatResult structs, inline validators for grid size, iteration count, and repeat count, and makeBenchSim which seeds a deterministic checkerboard WaveSimulation2D_Real with a warm-up step.
runWavePerf, runWavePerfLoadsOnly, runWavePerfRepeat implementations
src/fl/math/wave/wave_perf_bench.h
Implements the three benchmark entry points: timed update() loop with per-cell and FPS metrics; memory-bound loads-only baseline reading all inner cells into a volatile sink; and repeat-stability measurement computing mean, variance, and std-dev via an inlined Newton-Raphson square-root. Closes fl::wave_perf and fl namespaces.
RPC handler refactor to delegate to wave_perf helpers
examples/AutoResearch/AutoResearchRemote.cpp
Swaps include to wave_perf_bench.h. Refactors perfProbeRepeat to select stencil enum and call runWavePerfRepeat, populating JSON from WavePerfRepeatResult. Refactors wave2dPerf to dispatch to runWavePerf or runWavePerfLoadsOnly based on loads_only, setting response fields from WavePerfResult.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AutoResearchRemote
  participant wave_perf

  rect rgba(100, 149, 237, 0.5)
    Note over Client,wave_perf: perfProbeRepeat RPC
    Client->>AutoResearchRemote: perfProbeRepeat(stencil_name, W, H, iterations, repeats)
    AutoResearchRemote->>wave_perf: runWavePerfRepeat(W, H, iterations, repeats, stencil)
    wave_perf-->>AutoResearchRemote: WavePerfRepeatResult{success, mean_us, std_dev, std_dev_pct}
    AutoResearchRemote-->>Client: JSON response
  end

  rect rgba(144, 238, 144, 0.5)
    Note over Client,wave_perf: wave2dPerf RPC
    Client->>AutoResearchRemote: wave2dPerf(stencil_name, W, H, iterations, loads_only)
    alt loads_only
      AutoResearchRemote->>wave_perf: runWavePerfLoadsOnly(W, H, iterations, stencil)
    else
      AutoResearchRemote->>wave_perf: runWavePerf(W, H, iterations, stencil)
    end
    wave_perf-->>AutoResearchRemote: WavePerfResult{success, total_us, us_per_update, fps}
    AutoResearchRemote-->>Client: JSON response
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐇 A bunny hops through benchmark land,
Where timing loops once cluttered hand.
Now runWavePerf takes the stage,
And RPCs delegate with sage!
Mean, std-dev, and Newton's root—
All neatly packed, oh what a hoot! 🌊

✨ 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 refactor/wave-perf-bench-external

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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 16, 2026
@zackees
zackees merged commit 3e14cd2 into master Jun 16, 2026
6 of 8 checks passed
@zackees
zackees deleted the refactor/wave-perf-bench-external branch June 16, 2026 01:40
@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.
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