Repository navigation
Description
What
The port_comparison bench compares each Rust port with the C oracle (rust/obs-c-oracle). The oracle's C is not built like shipped libobs:
Shipped libobs (RelWithDebInfo, build-project.yaml) |
Oracle under cargo bench |
|
|---|---|---|
| GCC / Clang | -O2 -g |
-O3 (cc takes the level from the bench profile, opt-level 3) |
| MSVC | /O2 /Ob1 |
/O2 |
| Contraction | compiler default (Apple clang on arm64 fuses a * b + c into fmla) |
-ffp-contract=off (build.rs:439) |
The difference in the optimization level changes the results. We ran the whole port_comparison bench on master 88d49a9 twice per machine: as it is (-O3), and with CFLAGS=-O2 (cc puts CFLAGS after its own -O3; the machine code confirms it, see below). The Rust is the same in both runs and is the control for noise.
| Machine | Cases | Rust noise (median, p90) | C at -O2 ≥ 2× slower |
1.1–2× slower | ≥ 10 % faster |
|---|---|---|---|---|---|
| Ryzen 9 5950X, Linux, GCC 14.2 (pinned to one core) | 310 | 0.4 %, 4.9 % | 17 | 14 | 11 |
| Apple M1 Max, macOS, Apple clang (not pinned) | 310 | 0.9 %, 5.3 % | 6 | 15 | 3 |
The large changes, mean time per iteration:
| Case | Machine | C -O3 |
C -O2 |
Rust | Rust/C -O3 |
Rust/C -O2 |
|---|---|---|---|---|---|---|
audio_mix_scene_mix_add_whole_tick |
Linux | 64.4 ns | 236.2 ns | 65.7 ns | 1.02 | 0.28 |
audio_mix_scene_mix_with_buf_whole_tick |
Linux | 93.6 ns | 350.6 ns | 98.8 ns | 1.06 | 0.28 |
audio_mix_source_volume_block_stereo |
Linux | 254.2 ns | 935.2 ns | 249.9 ns | 0.98 | 0.27 |
audio_mix_mix_whole_tick (audio output tick) |
Linux | 1.06 µs | 3.28 µs | 1.03 µs | 0.97 | 0.31 |
format_yuy2_to_uyvx_1080p |
Linux | 150.0 µs | 588.6 µs | 1165.1 µs | 7.77 | 1.98 |
format_i420_to_uyvx_1080p |
Linux | 285.9 µs | 612.0 µs | 648.7 µs | 2.27 | 1.06 |
format_uyvx_to_nv12_1080p |
macOS | 901.5 µs | 5288.7 µs | 1215.4 µs | 1.35 | 0.22 |
format_uyvx_to_i444_1080p |
macOS | 1203.2 µs | 5049.4 µs | 1530.8 µs | 1.27 | 0.30 |
- Linux: the 17 cases at ≥ 2× are the audio mix and volume loops (obs-scene: Port the scene audio mix kernels (#3079) #3092, obs-source: Port the source volume multiply kernels (#3080) #3093 and the output tick mix) and the decompress conversions to UYVX. GCC vectorizes these loops at
-O3. At-O2, GCC 12 and later vectorize only with the "very cheap" cost model, which rejects a loop that needs a run-time check that two pointers do not overlap, so these loops stay scalar. Inoracle_obs_scene_audio_mix_add, the-O3build hasaddps; the-O2build has onlyaddss. - macOS: clang vectorizes the audio loops at
-O2too (oracle_obs_scene_audio_mix_addhas the same instructions in both builds), so they do not change. The six cases at ≥ 2× are the compress conversions from UYVX, through SIMDe's SSE on arm64. - So for these cases the bench reports the wrong conclusion: on Linux the audio ports look level with C but are 3–4× faster than the shipped C, and the decompress gap looks like up to 7.8× but is up to 2× against the shipped C. On macOS the compress ports look 1.3× slower but are 3–5× faster.
- The small changes (below 2×) are mostly cases of a few nanoseconds. The cases where the C is faster at
-O2are in that group too.
To get the shipped numbers today, a PR author must build a second C by hand (as in #3092 and #3093). The 2026-10-30 baselines in docs/rust-port/benchmarks/ have the same bias, and rust/tools/benchmarks/record.py records only profile: "bench (release, opt-level 3)", not the C flags.
Proposed
- In
rust/obs-c-oracle/build.rs, build the oracle C at the shipped level when the profile is optimized:-O2for GCC/Clang (ccopt_level(2)whenOPT_LEVELis 2 or more). MSVC stays at/O2. The Rust side stays at opt-level 3, as the shipped staticlib (libobs/cmake/rust.cmake, profilerelease).- Do not use a Cargo override such as
[profile.bench.package.obs-c-oracle] opt-level = 2. The bench target and its Rust wrappers are inobs-c-oracle, so the override would also lower the Rust that the bench measures where LLVM inlines it into the bench crate.
- Do not use a Cargo override such as
- Keep
-ffp-contract=off. Tier 3 compares bits with the Rust, which never fuses; a fused oracle would make parity on arm64 impossible. Write indocs/rust-port/release-criteria.md("Record C/Rust benchmark evidence") that the bench C is strict IEEE, and that on macOS arm64 the shipped C fuses and can be a little faster. - Add the C compiler flags to the
record.pyoutput (for example"c_flags": "-O2 -ffp-contract=off -fno-strict-aliasing"), and record the 2026-10-30 Linux, macOS and Windows baselines again. - Optional, separate PR: a second C build "as shipped" (compiler default contraction) for the bench only, to measure the fused arm64 case.
Tests
- RED: a check (
ci/test_benchmark_record.pyor a build.rs unit test) that the oracle's C flags in an optimized profile contain-O2and not-O3, and that the record has thec_flagsfield. - Tier 3: no change in results expected. The optimization level does not change IEEE results for the ported code, except NaN payloads where two NaNs meet, which the parity tests already accept (obs-source: Port the source volume multiply kernels (#3080) #3093). Run the full parity suite in the release profile to confirm.
- Bench: the cases in the table above give the
-O2numbers without a second hand build.
Notes
- Tier 3 under
cargo testbuilds the oracle at-O0and is not affected. - Windows was not measured again: cc already gives MSVC
/O2, the level that ships. - Found while measuring obs-scene: Port the scene audio mix kernels (#3079) #3092 and obs-source: Port the source volume multiply kernels (#3080) #3093 (perf: libobs: vectorize scene audio mixing and source volume multiply when ported #3007).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Oct 31, 2026
Claiming: investigation (worker tick, obs-studio4).
Plan, one branch
fix/3127-oracle-shipped-opt-level:ci/test_benchmark_record.pywith the oracle-flags contract — in an optimized profile theobs-c-oracleC compile carries-O2(GCC/Clang) and not-O3,-ffp-contract=offstays, andrecord.pyemits ac_flagsfield. It fails on current master (build.rs takes cc's default from the bench profile =-O3; noc_flagsin the record).rust/obs-c-oracle/build.rsclamps an optimized profile's C opt level to 2 via ccopt_level(2)whenOPT_LEVEL>= 2; MSVC stays/O2.record.pyrecords the flags actually used.docs/rust-port/release-criteria.md: state that the bench C is strict IEEE (-ffp-contract=off) while the shipped C fuses on macOS arm64, so a small shipped-C advantage there is expected.First PR within this tick.
zackees commentedon Oct 31, 2026
/ready
zackees commentedon Oct 31, 2026
Draft PR #3130 (worker tick, obs-studio4),
fix/3127-oracle-shipped-opt-level.ci/test_benchmark_record.pygains the flags contract and fails on master (noC_FLAGS/report_metadata, no clamp in build.rs).build.rsclamps the oracle's C toSHIPPED_C_OPT_LEVEL = 2when the profile is optimized and folds the level into the oracle input hash;record.pyemitsc_flags;release-criteria.mddocuments strict-IEEE bench C vs the fusing shipped macOS arm64 C.addssinoracle_obs_scene_audio_mix_add(shipped-C shape; the-O3build hadaddps);cargo bench ... -- --testSuccess;ci/local_gate.py --only self-testok; 11/11 recorder tests pass.Refs: re-recording the 2026-10-30 baselines at the shipped level needs the three machines; Linux can be done on a quiet host, macOS/Windows cannot from here.perf(bench): build the oracle C at the shipped optimization level (ob…