Skip to content

perf: vectorize noise-gate levels and gain with exact state parity - #85

Draft
chriscoveries wants to merge 4 commits into
review/base-noise-gate-20261016from
perf/noise-gate-exact-20261016
Draft

chriscoveries wants to merge 4 commits into
review/base-noise-gate-20261016from
perf/noise-gate-exact-20261016

Conversation

@chriscoveries

Copy link
Copy Markdown
Owner

Scope

Fork-only review, refs #27. A clean, independently usable noise-gate slice of the performance work on 087a25c7d977ad3fbcc12a572d95ec05042824de. No history from the old approximate dynamics experiment is reused. Compressor, limiter, expander, public APIs and workflows are unchanged. No upstream-connected branch or upstream discussion is modified.

The ordinary production callback calls a private sample-processing helper. SSE2 processes four channel-level and gain values at a time; the gate's state machine keeps the original scalar operation order. Overlapping channel planes and NaN-containing blocks use the original scalar sample order. Mono and non-SSE2 platforms retain scalar processing. There is no allocation in the processing loop.

Test-first commits

  • Characterization and scalar extraction: a8d986121bc259b9c3e702dc9fcd9da89997930a.
  • Test-only RED: 67d8854ea6af74e2c26ec314963a1a3ddc00d3c0.
  • GREEN source: 5d3911a7b57c7f209f17aad0aa18b69ae480fcd6.
  • Final handoff/evidence commit: d4ccac3f845734b6f918f0a9170092999556bf26, subject starts with review:.

Exact RED output:

sse2_processes_disjoint_full_vectors: expected 8 SIMD frames
noise_gate_process: checks=324216 failures=1
exit=1

The new CTest executable compares actual samples, untouched tails and carried state bit-for-bit with the original scalar loop under the same block partitions. Coverage includes 1–8 channels, 8/44.1/48/192 kHz, lengths 0–1025, long quiet/burst transitions, threshold equality, zero-time parameters, inverted thresholds, signed zero, subnormals, infinities, quiet NaNs, and exact/partial channel-plane overlap.

Observed locally:

Clang 17 optimized: noise_gate_process: checks=324216 failures=0
Clang 17 ASan/UBSan: noise_gate_process: checks=324216 failures=0
GCC 14.2 optimized: noise_gate_process: checks=324216 failures=0
scalar fallback (-U__SSE2__): checks=324215 failures=0
minimal CMake driver: test_noise_gate_process 1/1 Passed

Mutating the overlap guard caused 13 failures; disabling the NaN fallback caused 2,627; using current instead of previous level for the close decision caused 117,777. Each exited 1. The production header was restored and its blob verified: a2b04dc2e5b00eae36164b4255871e9458d2b812.

Indicative speed-up (not a measurement on the reviewer's hardware)

AMD EPYC 9V74 80-Core Processor; Linux container exposes 5 logical CPUs, affinity 5; Linux 6.18.44; Clang 17.0.0; -std=c11 -O2 -DNDEBUG -fno-fast-math -ffp-contract=off.

The adapter reuses the exact shared tools/ab_bench/core.py from fork #70, blob 9fc69edd742c3c10c247da7cbfd0d0fbca10aeb9. Nine AB/BA rounds per case, warm-up, 8,192 measured 1,024-sample blocks per side per round. Output/state equality is checked before timing; final output/checksum equality is checked every round. Raw per-round JSON and receipt are in the final review commit.

48 kHz case Scalar median (IQR), ns/block SSE2 median (IQR), ns/block Median paired speed-up IQR overlap
Stereo 7174.35 (485.18) 4874.94 (135.04) 1.4553x No
5.1 8596.18 (781.38) 4479.10 (261.29) 1.9661x No

Aggregate busy load was 0.0% before; during median 20.31%, range 18.75–21.88%. During-load includes the benchmark. No process identities were collected. This is one indicative virtualized-environment microbenchmark, not an end-to-end result or a prediction for the owner's Mac.

For the noise-gate portion alone of a stereo mic plus 5.1 desktop pipeline: 48000/1024 = 46.875 blocks/s per track. ((7174.3472−4874.9386)+(8596.1787−4479.0997))*46.875/1e6 = 0.30077 CPU-ms/s saved. At 60 fps that is 0.005013 CPU-ms/frame, or 0.03008% of a 16.6667 ms frame budget. Other filters and video work are not included.

Run without timing

bash test/review/noise-gate/run.sh --check
# SSE2 check under an existing Rosetta installation
arch -x86_64 /bin/bash test/review/noise-gate/run.sh --check

The standalone test needs no OBS process, hardware device or external dylib. Native arm64 exercises scalar fallback only. The runner never commits, pushes or dispatches CI. The timing adapter is explicit Linux-only opt-in.

Required formatting checks: blocked

clang-format-22 --dry-run --Werror: command not found; exit=127
gersemi --check: command not found; exit=127
soldr cargo fmt --check: command not found; exit=127
soldr cargo clippy --all-targets -- -D warnings: command not found; exit=127

Pinned formatter retrieval was attempted and failed on package-host DNS. These checks are outstanding, not passing. No Rust source changed.

Remaining gates and recommendation

Full OBS OFF/ON module builds, native platform checks and the required format/lint tools remain to run. The minimal CMake driver is not a full OBS build. Floating-point exception flags and signaling-NaN traps are outside the tested contract. Keep improving until those gates pass. The kernel improvement is measurable here; the overall streaming CPU saving is modest. All runners, notes and raw measurements are isolated in the final review: commit.

Move the private gate state and scalar processing into a shared inline unit. Preserve the existing transition order and compare samples and carried state against the original scalar loop, including overlapping channel planes and exceptional input values.
Enable the SIMD-path assertion on x86-64. The scalar characterization returns zero vector frames, so sse2_processes_disjoint_full_vectors fails with expected 8 SIMD frames. All sample and carried-state parity checks remain enabled.
Process four samples per SSE2 block while retaining the scalar state-transition order. Use the original sample loop for overlapping planes, NaN-containing blocks, mono and scalar tails. Keep both gain application and carried state bit-identical to the scalar reference in the differential tests.
Add a correctness-only runner and an explicit Linux timing adapter using the shared A/B statistics code. Retain raw interleaved rounds, environment/load metadata, mutation results and the remaining format and native-module gates.
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