Skip to content

perf(bench): Record the SIMD candidates and repair the benchmark recorder (#3003) - #3029

Merged
zackees merged 5 commits into
masterfrom
perf/3003-simd-benchmarks
Oct 30, 2026
Merged

zackees merged 5 commits into
masterfrom
perf/3003-simd-benchmarks

Conversation

@vpacher

@vpacher vpacher commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Fixes #3003

What and why

#3009 needs before and after numbers for every SIMD kernel. This PR adds the three candidate categories to the paired Rust-vs-C benchmarks and records a baseline on two machines.

record.py did not run on master. Its inventory check required the bench group prefixes to equal its 14 categories (#142). The port benches added since #1997 bring about 38 more prefixes, so a full run stopped with "incomplete benchmark inventory", and the release-criteria step "Record C/Rust benchmark evidence" could not be done. Its source fingerprint also missed most port crates, among them obs-media-io, obs-audio-controls and obs-core. Changes:

  • CATEGORIES is the required set; other groups are recorded too. format, volmeter and audio_mix join it.
  • --category (repeatable) runs and requires only the named categories, for the before and after numbers of one kernel.
  • The fingerprint covers all of rust/ (build directories excluded).
  • cpu_name() names the chip on macOS (sysctl); platform.processor() is only arm there.

Benches (rust/obs-c-oracle/benches/port_comparison/). Before timing, each case checks that both sides give the same result.

  • format.rs: the six format-conversion entry points on 1080p linesizes, each against the C as it ships (SSE2 on x86) and against the same C on the plain-C SSE stand-ins (format/<case>_c_scalar/1080p). Both sides write the same bytes.
  • volmeter.rs: get_sample_peak() and get_true_peak() on one tick (1024 frames). The C kernels are static, so oracle/audio_controls.c exports two wrappers; obs-audio-controls makes its peak module public (#[doc(hidden)], as obs-media-io's test hooks). The results are bit-identical: the first function-level comparison of the two kernels with the C.
  • audio_output_tick.rs: the output clamp (clamp_audio_output, to [-1, 1] and NaN to 0) is a step of the tick, not an entry point, so it is measured inside one audio_tick() with 6 mixes of planar stereo with clipped samples and NaNs. The clamped samples are bit-identical.

Differences from the issue text:

Baselines

docs/rust-port/benchmarks/baseline-2026-10-30-linux-x86_64.json and -macos-arm64.json: record.py, 5 complete runs, 302 pairs each, measured on ccce18950 (this branch before the rebase onto ad178c3). Between the two, the fingerprinted trees changed only in rust/tools/linux-validate/ (Tier 2 tooling, no .rs, .c, .h or .toml file), so the benchmarked sources are the same.

  • Linux x86_64: AMD Ryzen 9 5950X, LXC container on a Proxmox host, pinned to one core (--cpu 27) that no other guest uses, GCC.
  • macOS aarch64: Apple M1 Max (MacBook Pro), not pinned, Apple clang. This run came before the cpu_name() fix and wrote "cpu": "arm"; the chip name was filled in from sysctl -n machdep.cpu.brand_string. Every other field is as recorded.

Rust/C medians (below 1: Rust is faster):

Case Linux, vs SSE2 C Linux, vs scalar C macOS, vs C
format/uyvx_to_i420 4.00 0.10 1.40
format/uyvx_to_nv12 5.22 0.10 1.35
format/uyvx_to_i444 3.89 0.07 1.24
format/i420_to_uyvx 3.21 3.20 1.46
format/nv12_to_uyvx 2.45 2.36 1.04
format/uyvy_to_uyvx 1.53 1.48 1.15
format/yuy2_to_uyvx 1.58 1.52 1.13
volmeter/sample_peak/1024 7.16 1.33
volmeter/true_peak/1024 0.97 0.61
audio_mix/mix_whole_tick 1.03 0.99
audio_mix/mix_from_frame_300 0.97 0.85
audio_mix/output_tick/stereo_6_mixes 0.30 0.96

On macOS both C builds run the stand-ins, so the two C columns are the same; one is shown.

Findings for #3004 to #3006

RED → GREEN

  • RED: 07ad543 (ci/test_benchmark_record.py: 2 failures, 4 errors on the old record.py: the port groups next to the categories are refused, the SIMD categories are not required, the fingerprint misses obs-media-io, no filter). cd7d1c2 (macOS CPU name: 1 error).
  • GREEN: 89f4e1a and 42ebfa1, 7/7. soldr cargo bench -p obs-c-oracle --bench port_comparison -- --test passes on Linux x86_64 (600 benches, 0 failures) and on macOS aarch64.
  • Real app: N/A (bench and tooling only).
  • Test cost: one new ci/ test file, 7 cases, 0.7 s; no Rust test added.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • User-visible change: not applicable (bench and tooling only)
  • (Optional) Local gate passed and the pushed head is stamped
  • Warning or flag changes: not applicable
  • Intentional differences from C: not applicable (no port)

🤖 Generated with Claude Code

vpacher and others added 5 commits October 30, 2026 09:20
…er (#3003)

record.py requires the bench group prefixes to equal its 14 categories,
but the port benches added since #1997 bring about 38 more, so a full run
stops with "incomplete benchmark inventory". Its source fingerprint also
misses most port crates, among them obs-media-io, obs-audio-controls and
obs-core.

The test asks for: the categories as a required set with other groups
allowed; format, volmeter and audiomix among them (#3009); every Rust
crate in the fingerprint; and a filter that runs only some categories.
It fails on the current record.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… inventory (#3003)

record.py:
- CATEGORIES is the required set: a full run needs all of them and
  records the bench groups of the ports too. format, volmeter and
  audio_mix join it as the SIMD candidates of #3009.
- --category (repeatable) runs and requires only the named categories,
  for the before and after numbers of one kernel.
- The source fingerprint covers all of rust/ (build directories
  excluded), so a change in any port crate during a run is found.

Benches (rust/obs-c-oracle/benches/port_comparison/):
- format.rs: the six format-conversion entry points on a 1080p frame,
  each against the shipped C (SSE2 on x86) and against the same C on the
  plain-C SSE stand-ins. Both sides must write the same bytes.
- volmeter.rs: sample peak and true peak of one tick (1024 frames).
  oracle/audio_controls.c exports the two static C kernels as
  oracle_get_sample_peak/oracle_get_true_peak; obs-audio-controls makes
  its peak module public (doc-hidden) for the benches. The results are
  bit-identical.
- audio_output_tick.rs: one audio output tick with 6 mixes of planar
  stereo, so the output clamp (to [-1, 1], NaN to 0) runs on clipped
  samples and NaNs. The clamped samples are bit-identical.

The mix add itself is already benched as audio_mix/mix_whole_tick and
mix_from_frame_300 (#1903), so the category is audio_mix, not a second
name. The RMS is not benched: #3009 keeps it scalar.

docs/rust-port/release-criteria.md describes --category and the
categories.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On Apple Silicon, platform.processor() is "arm", so the macOS baseline
of #3003 did not name its CPU. The test asks record.py's cpu_name() for
the chip from sysctl on macOS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
cpu_name() asks sysctl (machdep.cpu.brand_string) on macOS before it
falls back to platform.processor(); Linux still reads /proc/cpuinfo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two complete record.py runs (5 repeats, 302 pairs each) of ccce18950:

- baseline-2026-10-30-linux-x86_64.json: AMD Ryzen 9 5950X, an LXC
  container on a Proxmox host, pinned to CPU 27 (--cpu 27; no other
  guest on that core), GCC.
- baseline-2026-10-30-macos-arm64.json: Apple M1 Max (MacBook Pro), not
  pinned, Apple clang. This run came before the cpu_name() fix and wrote
  "cpu": "arm"; the chip name was filled in from
  `sysctl -n machdep.cpu.brand_string`. Every other field is as
  recorded.

No Windows baseline: the bench does not link on Windows (#3025).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=a252febde0ea3cd44bdd3876c9dafceaf3b51a61 secs=451 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793348886,"gate":"rust/all/fmt","host":"linux-x86_64","key":"047b439388daf6652ba2fc7cc19bb6ae2212a7813154b5cff23cf79a5dbb36c0","lane":"lint","parents":["42ebfa137875f873c9b7441580993de96b968d10"],"secs":70,"stamp":"369742f6da5b18008755653c16a6081b","tree":"a252febde0ea3cd44bdd3876c9dafceaf3b51a61","v":1,"via":"run"}
Ci-Attestation: {"at":1793348886,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"047b439388daf6652ba2fc7cc19bb6ae2212a7813154b5cff23cf79a5dbb36c0","lane":"lint","parents":["42ebfa137875f873c9b7441580993de96b968d10"],"secs":70,"stamp":"c0b7b0b95311280cb92c1c34767ae7cc","tree":"a252febde0ea3cd44bdd3876c9dafceaf3b51a61","v":1,"via":"run"}
Ci-Attestation: {"at":1793348886,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"1d840ac657569631fbd008fb222905f7a8fdd6dd789ef6a4f4a712374e7b2ab7","lane":"rust-test","parents":["42ebfa137875f873c9b7441580993de96b968d10"],"secs":230,"stamp":"631fa3d07c4da50ad0fb7d11825ebda9","tree":"a252febde0ea3cd44bdd3876c9dafceaf3b51a61","v":1,"via":"run"}
Ci-Attestation: {"at":1793348886,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"d221d5165c6604f673c08f55b552160b9421c082125417f2eab0ffe090d49c1f","lane":"cross","parents":["42ebfa137875f873c9b7441580993de96b968d10"],"secs":151,"stamp":"ea82370c67c4ac8e926701c5a4a1819a","tree":"a252febde0ea3cd44bdd3876c9dafceaf3b51a61","v":1,"via":"run"}
Ci-Attestation: {"at":1793348886,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"d221d5165c6604f673c08f55b552160b9421c082125417f2eab0ffe090d49c1f","lane":"cross","parents":["42ebfa137875f873c9b7441580993de96b968d10"],"secs":151,"stamp":"f048068ada7be4db889b7dd429cc3842","tree":"a252febde0ea3cd44bdd3876c9dafceaf3b51a61","v":1,"via":"run"}
Ci-Attestation: {"at":1793348886,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"d221d5165c6604f673c08f55b552160b9421c082125417f2eab0ffe090d49c1f","lane":"cross","parents":["42ebfa137875f873c9b7441580993de96b968d10"],"secs":151,"stamp":"07717457768af8484a418c7f5fdae6b3","tree":"a252febde0ea3cd44bdd3876c9dafceaf3b51a61","v":1,"via":"run"}
Ci-Attestation: {"at":1793348886,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"d221d5165c6604f673c08f55b552160b9421c082125417f2eab0ffe090d49c1f","lane":"cross","parents":["42ebfa137875f873c9b7441580993de96b968d10"],"secs":151,"stamp":"0e4493593bb124e8fa0ad4c0e0c0ff99","tree":"a252febde0ea3cd44bdd3876c9dafceaf3b51a61","v":1,"via":"run"}
Ci-Attestation: {"at":1793348886,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"26a3e1e83f81c55c8647114a6db1d5beb7e5fb2ab276f284dddf53fa37cdbe19","lane":"tier2-linux","parents":["42ebfa137875f873c9b7441580993de96b968d10"],"secs":408,"stamp":"014d239d86372118c94e144ef3d42d1e","tree":"a252febde0ea3cd44bdd3876c9dafceaf3b51a61","v":1,"via":"run"}
@vpacher
vpacher marked this pull request as ready for review October 30, 2026 08:40
@vpacher

vpacher commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Ready for review. CI is green (CI Gate ✅); the pushed head ae654b9 is stamped by the local gate (lint, rust-test, cross, tier2-linux), so PR CI skipped the Linux unit-test lanes.

Auto-merge is off on purpose: please comment before it merges, in particular on the findings for #3004 to #3006 in the description (no caller of the format conversions in OBS; the decompress gap is not SIMD; sample_peak 7x on x86). Follow-ups filed: #3025 (the bench does not link on Windows), #3031 (decompress_422 converts twice the row).

@vpacher
vpacher requested a review from zackees as a code owner October 30, 2026 08:40

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: LGTM. RED → GREEN (ci/test_benchmark_record.py 7/7), and every bench checks that both sides give the same output before it times anything. The record.py fix (required categories as a subset, the fingerprint covering all of rust/, --category) repairs a release-criteria step that had been broken on master. Two named machines, 5 runs each. The findings change #3009's priorities; I will update it there. Queuing.

@zackees
zackees added this pull request to the merge queue Oct 30, 2026
Merged via the queue into master with commit 2a1fcf3 Oct 30, 2026
36 checks passed
@zackees
zackees deleted the perf/3003-simd-benchmarks branch October 30, 2026 08:52
zackees added a commit that referenced this pull request Oct 31, 2026
The three decompress conversions called the generic Source/Sink traits
per pixel: for i420_to_uyvx that was two u8 reads and two u32 writes per
output pixel, each one bounds-checked and copied through a fixed-size
array, against a C loop that walks row pointers. Measured 1.5-3.2x the C
(#3029's baselines).

Source gains bytes(offset, len): the row as a slice, once per row, and
the pixel loops index it. RawSource builds the slice from the caller's
pointer under the same safety contract as read(). The write side stays
offset-addressed, because output rows may overlap each other (#3031), but
each pair of adjacent pixels is now one 8-byte store like the C's two
adjacent uint32_t stores, in the C's order.

Parity is unchanged: obs-media-io's 284 lib tests pass, including
format_conversion_parity against the C, the _c_scalar stand-ins and the
shim, and decompress_422_one_row (the #3031 overlap fixture).

Local format ratios (rust/C, best of two record.py runs on a loaded
Ryzen 7 3700X; the untouched compress cases move 25% between runs, so
this box cannot demonstrate the 1.10 bound):
  i420_to_uyvx  1.43 -> 0.93
  nv12_to_uyvx  1.29 -> 1.17
  uyvy_to_uyvx  1.04 -> 1.35
  yuy2_to_uyvx  1.28 -> 1.02
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 31, 2026
…rust#3111) (obs-rust#3114)

The three decompress conversions called the generic Source/Sink traits
per pixel: for i420_to_uyvx that was two u8 reads and two u32 writes per
output pixel, each one bounds-checked and copied through a fixed-size
array, against a C loop that walks row pointers. Measured 1.5-3.2x the C
(obs-rust#3029's baselines).

Source gains bytes(offset, len): the row as a slice, once per row, and
the pixel loops index it. RawSource builds the slice from the caller's
pointer under the same safety contract as read(). The write side stays
offset-addressed, because output rows may overlap each other (obs-rust#3031), but
each pair of adjacent pixels is now one 8-byte store like the C's two
adjacent uint32_t stores, in the C's order.

Parity is unchanged: obs-media-io's 284 lib tests pass, including
format_conversion_parity against the C, the _c_scalar stand-ins and the
shim, and decompress_422_one_row (the obs-rust#3031 overlap fixture).

Local format ratios (rust/C, best of two record.py runs on a loaded
Ryzen 7 3700X; the untouched compress cases move 25% between runs, so
this box cannot demonstrate the 1.10 bound):
  i420_to_uyvx  1.43 -> 0.93
  nv12_to_uyvx  1.29 -> 1.17
  uyvy_to_uyvx  1.04 -> 1.35
  yuy2_to_uyvx  1.28 -> 1.02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

chore: perf: benchmark the SIMD candidates in record.py (format conversion, volume meter, audio mix)

2 participants