Skip to content

perf: audio: verify or force vectorization of mix add and output clamp #3006

Closed as not planned

Description

@zackees

What

Two element-wise audio loops that probably vectorize already, but nobody has checked:

  • rust/obs-core/src/audio_mix.rs:178 (mix_into, *mix += *aud). Runs 6 mixes × channels × 1024 frames every tick. C: libobs/obs-audio-mix.c.h:47-55.

  • rust/obs-media-io/src/ffi/audio_output.rs:283 (clamp_audio_output): clamp to [-1, 1] and NaN → 0, every tick per mix. C: libobs/media-io/audio-io.c.h:115. The is_nan branch may block vectorization.

  • Running today: the Rust, when the Rust ports are on.

  • Expected gain: low to medium.

  • Parity: the C is scalar, so output must stay bit-exact. Element-wise add, cmpord and min/max stay exact; no FMA.

Acceptance criteria

  • Assembly for both loops on x86_64 and aarch64 posted on this issue.
  • Where a loop isn't vectorized, restructure it (branchless clamp, chunked slices) or add a std::arch path in src/platform/.
  • The parity tests stay bit-exact, and the audiomix benchmark (sub-issue 1) shows no regression and, where code changed, a gain.

Failing-test sketch

RED: an assembly or benchmark check showing the clamp loop is scalar (no maxps/fmax vector op), or a benchmark bound on audiomix/clamp/1024 that fails.

Rules for this work (#756): portable stable Rust only (no std::simd/nightly), a scalar fallback with runtime CPU detection, ISA-specific code only in the crate's src/platform/ (Dylint ban_platform_cfg_outside_boundary). Tier 3 parity is bit-exact unless the C reference itself uses SIMD (docs/rust-port/testing-policy.md:296). RED then GREEN. Every kernel needs a benchmark in rust/tools/benchmarks/record.py first (sub-issue 1 of the meta issue).

Activity

  1. added
    enhancement
    P3
    size:S
    on Oct 30, 2026
  2. zackees commented on Oct 30, 2026

    @zackees
    MemberAuthor

    Triage: well defined (acceptance criteria and a failing-test sketch are in the body), but not Ready yet. It depends on #3003 (benchmark baseline in record.py), which is open. It becomes Ready once #3003 merges, and the baseline numbers decide whether this one is still worth doing.

  3. zackees commented on Oct 30, 2026

    @zackees
    MemberAuthor

    Closing per the #3029 baseline: the mix add is equal to the C on both machines, and the whole output tick with the clamp is already 3.3x faster in Rust on x86 (0.96x on aarch64). Nothing to gain. See #3009.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3enhancementsize:S

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions