Repository navigation
perf(bench): build the oracle C at the shipped optimization level (#3127) - #3130
Merged
Merged
Conversation
…3127) RED: the recorder has no c_flags field and build.rs leaves the oracle C at the bench profile's -O3. The three new cases fail: AttributeError: module 'record' has no attribute 'C_FLAGS' AttributeError: module 'record' has no attribute 'report_metadata' AssertionError: 'const SHIPPED_C_OPT_LEVEL: u32 = 2;' not found Refs #3127
) The bench profile is opt-level 3, so cc built the oracle's C at -O3 while the shipped libobs C is RelWithDebInfo (-O2 -g, /O2 on MSVC). GCC's -O2 cost model refuses the runtime-overlap check in the audio mix and volume loops, so the shipped C stays scalar where the -O3 oracle vectorized them: the bench called the Rust 3-4x faster than C on cases that are actually at parity, and reported up to 7.8x on conversions that are 2x against the shipped C. build.rs now clamps the oracle's C to SHIPPED_C_OPT_LEVEL (2) whenever the Cargo profile is optimized, and puts the level in the oracle input hash. The Rust side keeps the profile's opt-level 3, as its shipped release static library does; a [profile.bench.package] override would lower the Rust the bench measures too. -ffp-contract=off stays: Tier 3 compares bits with the Rust, which never fuses. record.py records c_flags so a baseline names the C it measured, and release-criteria.md says the bench C is strict IEEE while the shipped macOS arm64 C fuses, so a small shipped-C advantage there is expected. GREEN: objdump of the rebuilt oracle archive shows only addss (scalar) in oracle_obs_scene_audio_mix_add, the shipped-C shape, where the -O3 build had addps. soldr cargo bench ... -- --test: Success. uv run ci/local_gate.py --only self-test: ok. Baselines re-recorded on Linux only if a follow-up runs it; macOS/Windows need their own hardware. Refs #3127
Member
Author
|
Handed off to the coordinator. The Linux baseline is re-recorded at the shipped level (see the table in the description), HEAD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bench profiled the C at
-O3while users run-O2:cargo benchbuildsobs-c-oracleat opt-level 3, andcctook the level from the profile, whereas the shipped libobs isRelWithDebInfo(-O2 -g,/O2on MSVC). That is a measurement bug, not a Rust regression: on Linux the audio mix/volume loops look level with C in the bench (Rust/C 0.97–1.06) but the shipped C is 3–4× slower, and the decompress conversions looked up to 7.8× when they are up to 2× against the shipped C. macOS compress cases look 1.3× slower but are 3–5× faster.Fixes #3127
RED
ci/test_benchmark_record.pygainsCFlagsTest(three cases): the oracle C is clamped to the shipped level inbuild.rs, the recorder names the flags it measured, and the report carries them. On master:GREEN
rust/obs-c-oracle/build.rs:SHIPPED_C_OPT_LEVEL = 2; when the Cargo profile is optimized,oracle.opt_level(SHIPPED_C_OPT_LEVEL). The level is also folded into the oracle input hash so an archive at another level cannot be served stale. The Rust side keeps the profile's opt-level 3, which is its shipped level (libobs/cmake/rust.cmake, profilerelease); a[profile.bench.package.obs-c-oracle]override is deliberately not used because it would lower the Rust the bench measures. MSVC keeps/O2.-ffp-contract=offstays: Tier 3 compares bits with the Rust, which never fuses, and a fused oracle would differ on arm64.rust/tools/benchmarks/record.py:C_FLAGSrecords-O2 -ffp-contract=off -fno-strict-aliasing, emitted asc_flags; the report fields moved intoreport_metadata()so the contract is testable without running the bench.docs/rust-port/release-criteria.md: the bench C is strict IEEE while the shipped macOS arm64 C fusesa * b + c, so a small shipped-C advantage there is expected, not a regression.Evidence
Rebuilt oracle archive (
target/release/build/obs-c-oracle-*/out/libobs_c_oracle.a), disassembly of the case the issue names:addssonly — the shipped-C shape; the-O3build carriedaddps.Tiers
-ffp-contract=offis kept. Full parity run left to PR CI.Test cost (testing-policy §"Test time")
New tests: three cases, longest < 0.1 s, no own threads, no large allocations; they read
build.rsand callrecord.report_metadata().Baseline re-recorded at the shipped level (Linux)
uv run rust/tools/benchmarks/record.py --cpu 7 --repeats 5 --category audio_mix --category format --category conversions --output 3127-linux.jsonondea01fd00, affinity CPU 7,AMD Ryzen 7 3700X,gcc (GCC) 15.2.0,c_flagsrecorded as-O2 -ffp-contract=off -fno-strict-aliasing(32 complete comparisons, 5 paired repeats). Rust/C medians, against the-O2column of #3127's table (*= macOS row in the issue, re-run here on Linux):audio_mix_scene_mix_addaudio_mix_scene_mix_with_bufaudio_mix_source_volume_blockaudio_mix_mix_whole_tickformat_yuy2_to_uyvxformat_i420_to_uyvxformat_uyvx_to_nv12format_uyvx_to_i444The mis-measurement is gone: with the oracle at the shipped level the audio mix ports read 3-4x faster than C (0.25-0.30, where
-O3reported 0.97-1.06 "level"), andyuy2_to_uyvxreads 1.15 instead of 7.77. Two differences from the issue's table are host, not code: this box is a 3700X with GCC 15.2 (the issue used a 5950X with GCC 14.2), and GCC 15's cost model vectorizessource_volume_block/stereoat-O2too, so that case reads 0.78 rather than 0.27.Not re-recorded: the macOS and Windows baselines (they need those machines). Those are data refreshes only; this PR's change is host-independent, and the flags are now named in every report so a future run says which C it measured.