Repository navigation
perf(media-io): write UYVX rows through one borrowed slice (#3004) - #3163
Merged
Merged
Conversation
zackees
marked this pull request as ready for review
October 31, 2026 15:33
zackees
enabled auto-merge
October 31, 2026 15:33
Member
Author
|
Ready and on auto-merge. Local checks that ran on this branch: |
This was referenced Oct 31, 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_i444madefour
Sink::writecalls per 4-pixel block (two luma rows, two chromahalves), each a bound-checked fixed-size copy, and read each block through
Source::bytestwice. This borrows one row pair per output plane perythrough the new
Sink::bytes_mutand writes by index, so a row pair costs onebounds check instead of
blocksof them.convert_uyvx_to_i444also packs allthree channels from the same two 16-byte loads, as the C does; the first cut
here read each block once per plane (3x the input loads) and was 28 % slower
than master, which the last commit fixes.
No arithmetic, loop bound,
u32wrapping, read order or write order changes.The row-pair slice is taken as
lum_linesize + blocks * 4bytes, so a widththat is not a multiple of 4 still writes past
lum_linesizewhere the C does,in the C's order (row 0 then row 1 inside each block).
Evidence
GREEN:
OBS_PARITY_CASES=reduced soldr cargo test -p obs-media-io --lib tests::video::format_conversion— 32 passed, including the C-oracleparity proptests for all three functions and the zero-width case.
./lint: every lane passed exceptci/test_tier2_serial_cpus.py:: test_serial_tests_run_at_the_same_time_on_their_own_cpus(
1.97 not less than 1.8 : the two tests did not overlap) — a load-sensitivetiming test on a host running four worker checkouts. It passes alone
(
Ran 11 tests … OK), and this PR touches no CI code.soldr cargo fmt --allis clean.
RED is the measurement, not a failing test: the per-block writes are what the
numbers below were paying for.
formatbench,soldr cargo bench -p obs-c-oracle --bench port_comparison,branch and
masterrun back to back on the same host (Ryzen 7 3700X, GCC15.2.0, four worker checkouts resident), medians:
format/uyvx_to_i420/1080pformat/uyvx_to_nv12/1080pformat/uyvx_to_i444/1080pThe C column of each pair moves ≤ 5 %, so the Rust deltas are not host drift
beyond that. Against the
-O3oracle these cases are still ~1.5-1.9x, so thisRefs #3004 and does not close it.
The parked SIMD kernel does not help, measured twice
~/dev/obs-rust/3004-simd-wip.patch's SSE2/NEON block kernel was re-applied ontop of current master and on top of this row-write change, and measured both
ways (
format/uyvx_to_*/1080p, same host):nv12 3.70 ms vs master 1.66 ms.
nv12 3.70 ms (vs 1.40 scalar).
Returning a
Block { y, u, v: [[u8; 4]; 2] }from the kernel costs more thanthe scalar byte picks it replaces, in both shapes. A SIMD path that can win has
to store into the output rows inside the kernel (raw pointers, in
src/platform/) instead of handing 24 bytes back per block; that is the nextstep and is not in this PR.
Test cost: no new tests; the existing parity proptests cover the changed code
(longest run < 0.1 s with
OBS_PARITY_CASES=reduced, no own threads).