Skip to content

perf: cache phasor sample interval#81

Open
txbrown wants to merge 2 commits into
elemaudio:mainfrom
txbrown:perf/cache-phasor-sample-interval
Open

perf: cache phasor sample interval#81
txbrown wants to merge 2 commits into
elemaudio:mainfrom
txbrown:perf/cache-phasor-sample-interval

Conversation

@txbrown

@txbrown txbrown commented Jun 6, 2026

Copy link
Copy Markdown

Summary

  • Cache the phasor sample interval (1 / sr) when PhasorNode is constructed so each tick avoids spelling the reciprocal division in the hot path
  • Preserve existing phasor and sphasor output behavior, including sync reset handling
  • Add native CTest coverage plus a focused phasor benchmark target so the optimization is reproducible

Part of #8.

Performance evidence

Measured locally on macOS with AppleClang, Release (-O3/NDEBUG) native builds. The benchmark runs 512-sample blocks and reports median throughput across repeated runs.

Case main median samples/sec PR median samples/sec Delta
phasor 363.8M 364.6M +0.2%
sphasor 299.5M 297.2M -0.8%

Result: this benchmark does not prove a stable material speedup in optimized builds. The likely explanation is that the compiler can already hoist or strength-reduce the invariant reciprocal in this tight benchmark. The PR still makes the intended invariant explicit and adds a benchmark target to keep future quick-perf work measurable.

Reproduction commands:

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./out/ ../..
cmake --build . --target runtime_benchmarks --config Release -j 8
./runtime/runtime_benchmarks 512 500000 7

Test plan

  • cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./out/ ../..
  • cmake --build . --config Release -j 8
  • ctest --output-on-failure
  • ./build/native/runtime/runtime_benchmarks 512 500000 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant