Repository navigation
perf(audio_mix): fuse the mul_div64 divisions and gate the recorder's 1.10 bound (#3138) - #3141
Merged
Merged
Conversation
`audio_mix/buffering_add_one_tick` records 1.19-1.30x the C on this host, above the 1.10 bound, and the recorder reports it but exits 0, so nothing turns the breach into a check. Add the three cases the gate must satisfy: a pair over the bound is reported, one within the bound passes, and the `dstr/printf_control` pair is never a breach. Fails on this commit: `record.over_bound` does not exist.
…sh (#3138) `audio_mix/buffering_add_one_tick` recorded 1.19-1.30x the C on this host, above the 1.10 bound. Two things paid for it: - `mul_div64` took the quotient and the remainder through `checked_div` and `checked_rem`, each with its own 0 test, so LLVM could not fuse them into the single 64-bit `div` the C's `num / div` + `num % div` compile to. One early 0 check plus `wrapping_div`/`wrapping_rem` restores the fusion; `ticks_to_ms` gets the same shape (its 0 rate case is the check). - `deque_push_front` and the `Deque::push_front` chain were cross-crate calls the compiler could not inline, while the C's `deque_push_front` is header inline. `#[inline]` on the chain lets the push fold into `push_ticks`. Measured with `uv run rust/tools/benchmarks/record.py --cpu 7 --category audio_mix` on this host (Ryzen 7 3700X, shared box): | | Rust | C | ratio | |---|---:|---:|---:| | before (master) | 47.79 ns | 39.46 ns | 1.211 | | after | 45.87 ns | 40.06 ns | 1.145 | Still above the bound: the remaining gap is the FFI wrapper's struct copies and one extra call layer; the recorder now flags it (`--max-ratio`). Refs #3138
zackees
marked this pull request as ready for review
October 31, 2026 09:40
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 31, 2026
…tio (obs-rust#3138) (obs-rust#3153) * test(bench): RED: exempt audio_mix/buffering_add_one_tick by name (obs-rust#3138) obs-rust#3138 decided option 1: the pair is one extern "C" shim on a once-per-audio-tick call at ~46 ns against the C's ~39 ns, with no hot spot left after obs-rust#3141, so the Rust/C ratio bound does not apply to it (the 5% full-app bound of obs-rust#142 still does). The three cases the exemption must satisfy: the entry names the pair, its measured cost, the machine and the issue; an exempt pair is not a breach; and the pair stays in the report with its ratio. Fails on this commit: record.BOUND_EXEMPTIONS does not exist and summarize still marks the pair over the bound. * perf(bench): exempt audio_mix/buffering_add_one_tick from the 1.10 ratio (obs-rust#3138) obs-rust#3138 decided option 1: name the pair in record.py's BOUND_EXEMPTIONS with its measured absolute cost, the machine and the issue, instead of adding a push_ts_front fast path to the FFI layer. - over_bound() skips an exempt pair by name, so --max-ratio no longer fails on it; every other pair keeps the gate. - summarize() keeps the row and marks it exempt rather than over the bound, so the report still carries its ratio and absolute numbers. - The report records the exemption list, and the gate prints each exempt pair above the bound with its reason. - docs/rust-port/release-criteria.md documents --max-ratio and the list. Tests: 19 in ci/test_benchmark_record.py pass (three RED cases plus the gate print/exit paths).
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.
audio_mix/buffering_add_one_tick(theobs_audio_buffering_add()port) recorded 1.19–1.30x the C on this host, above the 1.10 bound. This PR removes two causes and makes the bound a check instead of a report row.RED
test(bench): RED: require an over-bound gate in the recorder (#3138)—ci/test_benchmark_record.py::BoundGateTestasks forrecord.over_bound. It fails on that commit withAttributeError: module 'record' has no attribute 'over_bound'.The perf half's RED is empirical, not a unit test (the box is shared and a Criterion run does not belong in PR CI):
record.py --category audio_mixon master recorded the pair over the bound, three repeats apart, as the issue does.GREEN
mul_div64took the quotient and the remainder throughchecked_divandchecked_rem, each carrying its own 0 test, so LLVM could not fuse them into the single 64-bitdivthat the C'snum / div+num % divcompile to. An early 0 check pluswrapping_div/wrapping_remrestores the fusion (and keeps the documented 0-divisor result).ticks_to_msgets the same shape.deque_push_front,with_dequeandDeque::push_front/push_front_srcwere cross-crate calls, while the C'sdeque_push_frontis header-inline.#[inline]on that chain folds the push intopush_ticks(confirmed in the disassembly: no call todeque_push_frontleft inpush_ticks).record.py --max-ratio Rprints every pair above R and exits 1;dstr/printf_controlis never a breach.Measured
uv run rust/tools/benchmarks/record.py --cpu 7 --category audio_mix --max-ratio 1.10 --output …, five paired repeats, medians:3e17f5d0dThe rest of the
audio_mixcategory stays inside the bound (0.26–0.98), so this change does not trade one pair for another. The reports were produced by the recorder on the shared box under load average 10–35; the ratio is the signal, the absolute numbers are not.Still above the bound. The residual is the FFI wrapper:
obs_audio_buffering_addcopiesstruct obs_audio_buffering(5 pointers) out and the state back, and keeps a call layer the C inlines (175 instructions against 102 plus a separatepush_buffering_ticks). Closing the last ~0.04 needs the shim restructured to hold the deque and state for one call — a separate, riskier change.--max-rationow fails the recording until then, so the breach cannot go quiet again.Tiers
soldr cargo test -p obs-data --test obs-tests-core --release audio_mix— 46 passed, includingobs_core::audio_mix_parity::buffering_matches(bit-exact vs the C)../lint: ok (146.6 s).Test cost: three Python cases in
ci/test_benchmark_record.py; the whole file runs in 0.4 s, single-threaded, no allocation or proptest.Refs #3138 (does not close it: the pair is still over the bound).