Skip to content

perf: experimental SIMD and dispatch work, plus a benchmark harness (unmeasured; looking for direction) #756

Closed

Description

@chriscoveries

Experimental, and mostly unmeasured. Our CI is in the repair shop (see our note on #699), so none of this has been through CI.

We have three fork branches with performance work. We link two of them; the third needs cleanup first. None is a pull request. None has before/after timings. We would like to know which, if any, you want before we open anything.

SIMD concept (illustration)

An illustration of the idea behind the first branch. It is not a result, and it shows no measurements.

1. Dynamics filters in SSE2: perf/27-dynamics-simd

What it changes. It adds plugins/obs-filters/dynamics-simd.h and uses it in the limiter, compressor, expander and noise gate. The envelope follower runs one channel per SSE2 lane, then takes the max across channels, as the scalar loop does. The gain stage uses vector log10 and 10^x polynomial approximations in place of mul_to_db and db_to_mul (libobs/media-io/audio-math.h:31-38, which call log10f and powf). The noise gate is split into three passes: max-abs across channels, the serial gate state machine, then a vector gain multiply. A new cmocka test, test/cmocka/test_dynamics_simd.c, compares each helper with the scalar code it replaced. 4 commits, 7 files, +818/-124.

Hot spots it targets (on master).

  • plugins/obs-filters/limiter-filter.c:124-151 (analyze_envelope) and :153-166 (process_compression)
  • plugins/obs-filters/compressor-filter.c:294-321 (analyze_envelope), :323-354 (analyze_sidechain) and :356-369 (process_compression)
  • plugins/obs-filters/expander-filter.c:275-320 (analyze_envelope), :322-374 (process_sample) and :377-407 (process_expansion)
  • plugins/obs-filters/noise-gate-filter.c:110-154 (noise_gate_filter_audio)

State. It merges cleanly into current master with no conflicts. It is 865 commits behind, so it needs a rebase before it could be a PR.

Measurement. None.

Things you should know.

  • The envelope pass is bit-identical to the scalar code by design, and the test checks that with a memory compare. The gain pass is not bit-identical. The compressor/limiter gain test allows 1e-5 relative error. The expander test allows 2e-2 relative error, and a comment in the test says the measured maximum was about 1.2e-2. So this changes the audio output slightly.
  • Mono input stays on the scalar path, because lane packing does not pay for one channel.
  • It uses SSE2 intrinsics directly, guarded by __SSE2__ / _M_X64. On arm64 the scalar loops still run.
  • We expect the user-visible gain to be small. These filters only run when a user adds them, and each is cheap per audio tick. We have not measured that either.
  • We can't point you to a passing run of the new test.

2. SIMD tier dispatch crate: perf/54-media-dispatch

What it changes. It adds a small Rust crate, rust/obs-simd (src/dispatch.rs, 271 lines). It detects CPU features at run time and picks a tier: AVX-512BW, AVX2, NEON or scalar. Detection is by feature bits, not CPU model. The result is cached. A thread-local override lets a test force a tier, and it refuses a tier the host lacks. There are unit tests per tier. rust/obs-media-io now depends on the crate. 2 commits, 6 files, +293.

Hot spot it targets. None yet. Nothing calls the crate, and it has no kernel to dispatch to. It is plumbing for later work. We have not picked a first user. The obvious candidate, libobs/media-io/format-conversion.c (for example compress_uyvx_to_i420 at :80), already uses SSE2 intrinsics. Outside the Rust port and its export list, nothing in the tree calls those functions.

State. It does not merge cleanly. Two files conflict: Cargo.lock, and the [dev-dependencies] block of rust/obs-media-io/Cargo.toml. Both look mechanical. rust/README.md changed on both sides but merged without conflict when we checked. Master has changed rust/README.md since, so we have not re-checked that file. It is 596 commits behind.

Measurement. None. There is nothing to measure yet.

Known gaps.

  • No SSE4.1 tier, so pre-AVX2 x86 hosts get the scalar tier.
  • No VNNI tier.
  • AVX-512 is detected as one bit (BW only).
  • No NEON dotprod or i8mm detection.
  • No documented example of how a kernel calls into a tier.

3. Benchmark harness (bench/harness on our fork, not linked: it needs cleanup before anyone reviews it)

What it changes. It adds bench/harness/ and bench/results-p0/. obs-bench.sh runs OBS headless under Xvfb with software GL. It records 60 seconds of x264 1080p30 from a fixed scene (a color source, a text source and a looping media source). It starts and stops the recording over obs-websocket, samples process CPU every 2 seconds, and writes one JSON file per run. build-t001.sh builds Release trees with ENABLE_RUST_LIBOBS off and on, side by side. make_charts.py draws bar charts. bench/results-p0/ holds nine run JSONs and per-run snapshots of the busiest processes. 14 commits, 35 files, +1073.

Hot spot it targets. None. It measures the whole app, not a function.

State. It only adds files, so it merges cleanly. It is 912 commits behind.

Measurement. These are the only numbers we have, and they do not support any claim.

  • They are nine 60-second runs from 11 Oct on one shared x86 server (Intel Skylake-SP), with other jobs running on it.
  • They compare the Rust libobs port off against on, at the harness's own base commit. They do not involve either branch above.
  • Average process CPU ranged from 103.6% to 484.6% between runs. That spread is far larger than any off-versus-on difference.
  • The results README says: "NO MEASURABLE CHANGE (shared-box noise)" and "Do not cite these numbers for speedups." We agree.

Limits.

  • The scene has no audio filters, so as written it cannot exercise branch 1. It is not a kernel benchmark either.
  • It is Linux and x86 only, and it hard-codes working paths under /srv.
  • obs-bench.sh kills any Xvfb on display :99 when it starts, so run it only on a box you own.
  • It needs a quiet machine. We did not have one.

Related work already on master. #668 added paired Criterion benchmarks of Rust shims against C oracles, a recorder (rust/tools/benchmarks/record.py), and a recorded baseline (docs/rust-port/benchmarks/baseline-2026-10-14.json). Those cover util, graphics and the codec parsers. They do not cover audio filters or media-io. docs/rust-port/release-criteria.md:23-28 also sets a 5% bound on a full-app recording workload. This harness could be one way to produce that number, but we have not tried to line it up with #668.

What is weak

  • No before/after timing on real hardware for any of the three.
  • No CI run on any of them, and no maintainer review.
  • Branch 1 changes audio output slightly, and nobody has listened to it.
  • Branch 1 is SSE2 only. It does nothing on arm64 or for mono.
  • Branch 2 has no user and an API that will change.
  • Branch 3 is Linux-only, noisy, and aimed at the whole app. Its one dataset is unusable.
  • All three are hundreds of commits behind master, and branch 2 has two merge conflicts.

What we are asking

  1. Which of these, if any, would you want upstream? Saying "none of them" is useful.
  2. Should the harness go first, so that every later perf claim comes with numbers? If so, should it be reworked to build on test: Benchmark Rust hot paths against C oracles #668 and the recording workload in the release criteria, instead of landing as it is?
  3. For the dynamics filters, is a small numeric difference in the gain stage acceptable (about 1e-5 for the limiter and compressor, up to about 1e-2 for the expander)? Or would you want bit-exact output, with only the envelope pass vectorized?
  4. For the dispatch crate, do you want it before it has a kernel, or only together with its first one?

Activity

  1. zackees commented on Oct 25, 2026

    @zackees
    Member

    /investigate

    Triage: thanks for asking before opening PRs. As written this is a request for direction, not yet a task. Whether the project wants it depends on numbers the issue says it doesn't have yet. Missing for Ready:

    1. Before/after measurements on at least one machine, from a harness a reviewer can rerun (the testing policy keeps timing off the shared CI machines, so a local script is the right shape).
    2. For each change you'd open: the scope of one PR and its acceptance criteria. For example: output matches the scalar path within a stated tolerance (a Tier 3 differential test against the C), and a stated speedup on a stated workload.
      With those posted here, it can be marked Ready, or escalated if it comes down to a direction choice the measurements don't settle.
  2. added
    needs-investigation
    on Oct 25, 2026
  3. moved this from Triage to Investigating in obs-rust Multiviewon Oct 25, 2026
  4. zackees commented on Oct 27, 2026

    @zackees
    Member

    Triage, second pass, after reading current master. Two of your four questions can be answered from the repo; the other two are priority calls only a maintainer can make.

    Settled by the repo

    • Q2 (harness). Don't land bench/harness as it stands. test: Benchmark Rust hot paths against C oracles #668 already put a recorder and a baseline on master — rust/tools/benchmarks/record.py (paired Criterion runs, five repeats, --cpu pinning) and docs/rust-port/benchmarks/baseline-2026-10-14.json — and the perf numbers they feed are specified in docs/rust-port/release-criteria.md:46-47 (hot paths within 10%, the full-app recording workload within 5%). The recorder's CATEGORIES set (rust/tools/benchmarks/record.py:20-24: bmem, dstr, vec2–4, crc32, avc, hevc, av1, decl, calldata, proc, signal, conversions) has no audio-filter entry, which matches your observation that audio filters are uncovered. Extending those two files is the shape a reviewer can rerun; a second harness with its own /srv paths is not.
    • Q3 (tolerance). docs/rust-port/testing-policy.md:296 is the governing rule: Tier 3 parity is exact bit equality where the C is scalar, and a per-function ULP tolerance is allowed only where the C itself uses SIMD. The four filters are scalar code (plugins/obs-filters/limiter-filter.c.h:118-166 on master; the issue's citations are stale only because master renamed .c to .c.h per BUILD.md). So bit-exact is the default: vectorize what stays bit-identical (the envelope pass, which your memory-compare test already pins) and leave mul_to_db/db_to_mul (libobs/media-io/audio-math.h:31-38) scalar. For scale: a 1.2e-2 relative gain error is about 0.10 dB, and 1e-5 is about 0.0001 dB.

    Missing for the definition of Ready

    1. One issue per unit. "Three branches plus a harness" has no concrete scope (Ready item 1); it is three tasks. Branch 1 is portable to an issue on its own; branch 2 (“no caller, API will change”) and branch 3 (whole-app harness, Linux/x86, one unusable dataset) each need their own.
    2. For branch 1, the failing-test sketch the RED policy wants: test/cmocka/test_dynamics_simd.c must be shown failing against unmodified master (the issue says no passing run can be pointed to, which is the same problem in reverse), and the bit-exact variant above is what it should assert.
    3. A before/after number from a harness that exists on master, not a new one: add the four filters to record.py's categories and post the medians and ranges for one machine with the CPU named.

    Decision needed: does the project want any of this at all — specifically, is SSE2 work on plugins/obs-filters in scope while that directory's port status is what it is, and would you take branch 2 (rust/obs-simd) only together with its first kernel? Both are priority calls, not something the tree answers. If the answer is "harness first", the item above is the whole of it and the other two issues can wait.

  5. added
    decision-needed
    on Oct 27, 2026
  6. zackees commented on Oct 27, 2026

    @zackees
    Member

    Escalating to the maintainer: both questions in this issue are priority calls about what the project spends time on, not something the tree answers. I researched it — here is what the repo does and does not settle, the options, and my recommendation.

    What the repo settles (already posted in the triage above): don't land bench/harness as its own thing (#668's rust/tools/benchmarks/record.py plus docs/rust-port/benchmarks/baseline-2026-10-14.json is the rerunnable shape), and Tier 3 parity for these filters is bit-exact, because the C is scalar (docs/rust-port/testing-policy.md:296).

    What it does not settle

    1. Is SSE2 work on plugins/obs-filters in scope at all? Nothing in CONSTITUTION.md, AGENTS.md or docs/rust-port/release-criteria.md says whether performance work on the C tree is welcome while the Rust port is unfinished. The only performance rule there is a bound on the port not being slower (release-criteria.md:46-47: hot paths within 10%, the recording workload within 5%), which does not authorize making the C side faster. The four filters are also not on any hot-path list, and a gain-stage approximation would change audio output by up to ~0.10 dB on the expander.
    2. Would rust/obs-simd be taken before it has a kernel? A dispatch crate with no caller and an API that its own author says will change is a maintenance cost in rust/, and the repo has no rule for how much unused Rust scaffolding it keeps.

    Options

    • A. Decline the perf work for now, and keep the door open: the port's perf rule is "not slower than C", and the observability gap (audio filters are absent from record.py's CATEGORIES) is the cheaper, more reusable piece. If anything lands, it is that: add the four filters to the existing recorder, as its own small task.
    • B. Accept branch 1 only, gated on the bit-exact variant (envelope vectorized, mul_to_db/db_to_mul scalar), plus a recorded before/after from record.py. That is one issue with a measurable acceptance criterion.
    • C. Accept all of it as three tasks, which means carrying an API-unstable dispatch crate and a second benchmark harness.

    Recommendation: A. The port owes a non-regression bound, not a speed-up, and neither the filters nor the dispatch crate is on a path anyone is waiting for. A is also fully reversible: if the maintainer later wants branch 1, the conditions above are already written out in the triage comment.

    How to answer: a comment whose first line starts Decided: (or Decision:) clears human-review-needed and resumes the work; removing the label by hand also works. I have swapped decision-needed for human-review-needed so this stops looking like something the coordinator can clear.

  7. added
    human-review-needed
    decision-needed
    and removed
    decision-needed
    on Oct 27, 2026
  8. moved this from Investigating to Needs decision in obs-rust Multiviewon Oct 27, 2026
  9. zackees commented on Oct 30, 2026

    @zackees
    Member

    Decided: A — decline the SIMD/dispatch/harness work for now; close this issue as not planned. The door stays open.

    Reasons:

    • The port owes a non-regression bound against C, not a speed-up: docs/rust-port/release-criteria.md:46-47 (hot paths within 10 %, recording workload within 5 %). Making the scalar C filters faster is outside what the port is measured on, and none of the four filters is on a hot-path list.
    • Tier 3 parity for these filters is bit-exact because the C is scalar (docs/rust-port/testing-policy.md:296). The gain-stage approximations (up to 2e-2 relative error on the expander) would not pass it.
    • A second benchmark harness duplicates test: Benchmark Rust hot paths against C oracles #668 (rust/tools/benchmarks/record.py, docs/rust-port/benchmarks/baseline-2026-10-14.json), and a rust/obs-simd dispatch crate with no caller and an unstable API is unused scaffolding in rust/.
    • Reversible: the conditions for coming back are already written in the triage above. Open a new issue for branch 1 alone, with the bit-exact variant (envelope vectorized, mul_to_db/db_to_mul left scalar) and a before/after recorded with record.py after adding the filters to its CATEGORIES. That issue would be Ready on arrival.

    Thanks @chriscoveries for asking before opening PRs.

  10. removed
    human-review-needed
    needs-investigation
    on Oct 30, 2026
  11. zackees commented on Oct 30, 2026

    @zackees
    Member

    Decided: accept SIMD work, on the condition that it is portable. This replaces the earlier decline (#756 (comment)), per the maintainer.

    Conditions:

    • Portable: one code path that builds and runs on every target we ship (x86_64, aarch64; Windows, macOS, Linux), with a scalar fallback and runtime feature detection where an ISA extension is used. No per-platform intrinsics outside the crate's src/platform/ boundary, and no nightly-only features (std::simd stays out until it is stable on our pinned toolchain).
    • Parity: the Tier 3 differential tests against the C oracle keep passing. Where vector math changes the float results, the PR states the tolerance and why, rather than loosening a test silently.
    • Measured: before/after timings from the existing benchmark recorder (test: Benchmark Rust hot paths against C oracles #668), not a second harness.
    • Sliced: one kernel or filter per PR, RED then GREEN, so each lands on its own.

    The first slice can be filed as its own issue and taken as Ready.

  12. zackees commented on Oct 30, 2026

    @zackees
    Member

    Decided (amendment to #756 (comment)): two corrections to the conditions.

    1. Parity is bit-exact unless the C itself is SIMD. docs/rust-port/testing-policy.md:296 governs: Tier 3 parity is exact bit equality where the C reference is scalar; a per-function ULP tolerance is allowed only where the C uses SIMD. So a vectorized gain stage that differs from scalar C (1e-5 limiter/compressor, up to 1e-2 expander, as reported above) does not pass as-is. Keep the envelope pass (bit-identical by design) or restructure the gain math so it stays exact.
    2. Benchmark first, then kernels. Before any SIMD kernel lands, add its target to CATEGORIES in rust/tools/benchmarks/record.py (test: Benchmark Rust hot paths against C oracles #668) and record medians and ranges on one named machine. The first kernel should be the one likely to move a real number: pixel-format conversion (libobs/media-io/format-conversion.c) is preferred over the dynamics filters, whose per-tick cost is small.

    A survey of other SIMD candidates in the tree follows in a separate comment.

  13. zackees commented on Oct 30, 2026

    @zackees
    Member

    SIMD survey of the tree (read-only; gains are estimates, nothing benchmarked or checked in disassembly).

    Today the C reference uses SIMD in six places: format conversion, the volume meter peak, game-capture, the aja/decklink audio repack, rnnoise's kiss_fft and the graphics math headers. No Rust code uses std::arch intrinsics, target_feature or std::simd.

    Ranked by likely user-visible gain

    # Where Runs Version running today Gain Bit-exact?
    1 Format conversion, rust/obs-media-io/src/format_conversion.rs:106-305 (C libobs/media-io/format-conversion.c.h is SSE2) per frame Rust, scalar per-pixel read/write: slower than the C it replaces High Integer; tolerance allowed (C is SIMD)
    2 Volume meter peak and true peak, rust/obs-audio-controls/src/peak.rs:16,28 (C uses SSE) every source, every tick Rust, scalar [f32;4] Medium Tolerance allowed; keep the C's lane order to stay exact
    3 Mix add, rust/obs-core/src/audio_mix.rs:178 6 mixes x channels x 1024 per tick Rust Low-med (check whether it already auto-vectorizes) Exact
    4 Output clamp and NaN-to-0, rust/obs-media-io/src/ffi/audio_output.rs:283 per tick per mix Rust Low (the branch may block vectorization) Exact with cmpord + min/max
    5 Volume meter RMS, rust/obs-audio-controls/src/volmeter.rs:252 every tick Rust Medium No: reordering the reduction; C is scalar
    6 Scene audio mixing, libobs/obs-scene.c.h:1330,1341 every item, every tick C Low-med Exact if not fused into FMA
    7 Source volume multiply, libobs/obs-source.c.h:4829,4838 per source, per tick C (the Rust port moves only the decisions) Low Exact
    8 Downmix, rust/obs-source/src/audio_input.rs:200-230 per packet when mono is on Rust Low Exact
    9 Pulse monitor volume, rust/obs-audio-monitoring/src/pulse_format.rs:316 per monitored packet Rust, a closure per sample Low-med Depends on how scale_s16 rounds
    10 Dynamics filters, EQ, gain, noise-suppress float/s16 conversion (plugins/obs-filters) per tick when added C Low Dynamics and EQ: no (state carried between samples). Gain and conversion: exact

    Little or nothing to gain: frame and plane copies (memcpy), GIF/LZW decode (serial), the FreeType blit and LUT load (run only on user action), and the encoders' CPU row copies.

    Rust doesn't have these yet: audio resampling (swresample) and software scaling and colorspace conversion (swscale) are still C wrappers around FFmpeg, which is already SIMD. A Rust replacement needs SIMD from day one, or it regresses.

    Proposed order:

    1. Benchmark format conversion and the volume meter in record.py.
    2. SIMD format conversion. It's the only place where the Rust port is behind the C today.
    3. Volume meter peak and true peak.
    4. Check the generated code for the mix add and clamp loops and force vectorization where it's missing.

    Each step is its own issue.

  14. zackees commented on Oct 30, 2026

    @zackees
    Member

    Tracking for the SIMD work is now meta issue #3009, with native sub-issues #3003 (benchmarks, which block the rest), #3004 (format conversion), #3005 (volume meter peak and true peak), #3006 (mix add and clamp vectorization), #3007 (scene mix and volume multiply when ported) and #3008 (SIMD guard for any swresample/swscale replacement).

  15. moved this from Needs decision to Triage in obs-rust Multiviewon Oct 30, 2026
  16. chriscoveries commented on Oct 31, 2026

    @chriscoveries
    ContributorAuthor

    Sorry for the long silence here; life got in the way of keeping up. Thank you and vpacher for turning this into #3009 and landing the baseline (#3029) and the first kernels so fast. That's a better plan than ours, so I'm closing this in favour of #3009.

    We still have some older perf work that might fit #3009's rules. If any of it is wanted, say which and we'll bring it up to those rules (record.py numbers on a named machine, bit-exact where the C is scalar, runtime detection with a scalar fallback, one kernel per PR) before opening anything:

    If none of these is worth the review time, that's a fine answer too.

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions