Home

dev / openkara

publicthedavidweng/OpenKara· sync paused
Overview Code History Branches Pull requestsIssuesInsights
main
HomeOverview Code PRsIssues

perf(separator): fixed per-chunk working memory for the spectral session (#172 PR 3) (#194)

2 months ago

9f742cc
Authored
Davy7/25/2026, 11:41:25 AM
* perf(separator): fixed per-chunk working memory for the spectral session (#172 PR 3)

Eliminate every steady-state heap allocation in the spectral transform
and composition path. Before: each chunk allocated ~33 MB (FourStem:
22 MB forward-transform output + 4 x 2.75 MB composed waveforms) to
~52 MB (TwoStem: + 24.75 MB spectral/time premix copies). After: the
first chunk sizes a persistent SpectralSessionState (plans + forward
buffer + one shared composition buffer + premix accumulators) and every
later chunk reuses it — pointer-stability tests pin this down.

- spectral: spec_into / ispec_into write into caller-owned buffers;
  the allocating spec / ispec become thin wrappers (golden-vector tests
  unchanged); byte-exact equivalence + no-reallocation tests added
- spectral_session: SpectralSessionState owns all chunk-loop buffers;
  composition is factored into compose_outputs_into_buffers, pure over
  the extracted core outputs, so the explicit FourStem/TwoStem layouts
  are unit-tested without an ORT session (correctness vs per-stem
  composition, buffer reuse across chunks)
- ORT inputs remain borrowed views over the reused buffers; ring
  feeding and OLA are untouched (StemMode semantics and 50% overlap
  unchanged; FFT implementation selection stays realfft f64 pending
  #170 measurements per the issue)

Verified against the published candidate artifact
(model-spectral-v1.0.0) and the dev waveform model: identical
equivalence numbers to the PR 2 baseline (single-window max-abs
<= 1.2e-5 all stems + premix; streaming end-to-end passes both modes).
cargo test --lib 1039 passed; clippy -D warnings and fmt clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(separator): make the forward-buffer restore genuinely unconditional

The take/restore of the reused forward-transform buffer had three ?
early-returns between them (borrowed tensor construction, session lock),
contradicting the 'even on error' comment. Move every fallible step into
the result closure so the restore cannot be skipped. Behavior after an
error is unchanged (the run aborts); the comment is now true.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>

Parent0a785a5

3 files changed
  • src-tauri/src/separator/inference.rs+7−6
  • src-tauri/src/separator/spectral.rs+52−4
  • src-tauri/src/separator/spectral_session.rs+273−75