Repository navigation
perf(media-io): borrow each UYVX block instead of copying it (#3004) - #3134
Merged
Merged
Conversation
The compress half read every 4-pixel block twice through `Source::read::<16>`, which returns a `[u8; 16]` by value: two 16-byte copies plus their bounds checks per block, the same per-access cost #3111 removed from the decompress half with row slices. `Source::bytes` already exists for that reason; `channel`/`average` only index the row, so they now take `&[u8]`. Nothing else changes: same loop bounds, same `u32` wrapping, same order of reads and writes, and `tests::video::format_conversion*` (32 cases, including the C-oracle parity proptests) is green. Measured on this host (Ryzen 7 3700X, GCC 15.2.0, `record.py --category format --repeats 5 --cpu 7`, min of 5 paired runs, master `81ac46b16` vs this branch, Rust medians): | case | master | branch | | |---|---:|---:|---:| | `format/uyvx_to_i420/1080p` | 2.31 ms | 2.12 ms | 1.09x | | `format/uyvx_to_i444/1080p` | 2.53 ms | 2.14 ms | 1.18x | | `format/uyvx_to_nv12/1080p` | 2.38 ms | 1.88 ms | 1.27x | The C column of the same runs stays within 7 %, which is what makes the Rust column comparable on a host carrying four worker checkouts. The compress cases are still far from the 1.10x bound, so this Refs #3004 rather than closing it; the SIMD work stays parked in `~/dev/obs-rust/3004-simd-wip.patch` with its own (negative) numbers. Refs #3004
zackees
marked this pull request as ready for review
October 31, 2026 08:24
Member
Author
|
Handed off to the coordinator.
No local-gate stamp: the branch's only change is one Rust source file and the PR run had already executed the full Linux gate. Refs #3004; the compress cases improve 1.09-1.27x but stay above the 1.10x bound, so the issue stays open for the SIMD kernels. |
This was referenced Nov 5, 2026
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.
What
compress_uyvx_to_i420,compress_uyvx_to_nv12andconvert_uyvx_to_i444read every 4-pixel block twice throughSource::read::<16>, which returns a[u8; 16]by value: two 16-byte copies plus their bounds checks per block. This borrows the block withSource::bytes(the method #3111 added for exactly this cost on the decompress half) and narrowschannel/averageto&[u8].No arithmetic, loop bound,
u32wrapping, read order or write order changes.Evidence
GREEN:
OBS_PARITY_CASES=reduced soldr cargo test -p obs-media-io --lib tests::video::format_conversion— 32 passed, including the C-oracle parity proptests for all three functions../lint—== lane lint: ok (150.7s).RED is the measurement, not a failing test: the per-block copy is what the numbers below were paying for.
uv run rust/tools/benchmarks/record.py --category format --repeats 5 --cpu 7, master81ac46b16vs this branch, min of 5 paired runs (Ryzen 7 3700X, GCC 15.2.0, host carrying four worker checkouts):format/uyvx_to_i420/1080pformat/uyvx_to_i444/1080pformat/uyvx_to_nv12/1080pThe C column of the same runs stays within 7 %, so the Rust deltas are not host drift; the rust-over-C ratio in
record.pyis not used here because the oracle on master is still the bench profile's-O3(the shipped-O2clamp is #3130, not merged yet).These three cases stay well above the 1.10x bound, so this Refs #3004 and does not close it. The parked SIMD attempt (
~/dev/obs-rust/3004-simd-wip.patch) is not in this PR: it was parity-clean but slower (3.40 -> 5.98 Rust/C onuyvx_to_nv12), and its numbers are on the issue.Test cost: no new tests; the existing parity proptests cover the changed code (longest run in the module < 0.1 s with
OBS_PARITY_CASES=reduced, no own threads).