Skip to content

perf(media-io): write UYVX rows through one borrowed slice (#3004) - #3163

Merged
zackees merged 3 commits into
masterfrom
perf/3004-uyvx-row-writes
Oct 31, 2026
Merged

zackees merged 3 commits into
masterfrom
perf/3004-uyvx-row-writes

Conversation

@zackees

@zackees zackees commented Oct 31, 2026

Copy link
Copy Markdown
Member

What

compress_uyvx_to_i420, compress_uyvx_to_nv12 and convert_uyvx_to_i444 made
four Sink::write calls per 4-pixel block (two luma rows, two chroma
halves), each a bound-checked fixed-size copy, and read each block through
Source::bytes twice. This borrows one row pair per output plane per y
through the new Sink::bytes_mut and writes by index, so a row pair costs one
bounds check instead of blocks of them. convert_uyvx_to_i444 also packs all
three 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, u32 wrapping, read order or write order changes.
The row-pair slice is taken as lum_linesize + blocks * 4 bytes, so a width
that is not a multiple of 4 still writes past lum_linesize where 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-oracle
parity proptests for all three functions and the zero-width case.

./lint: every lane passed except ci/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-sensitive
timing 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 --all
is clean.

RED is the measurement, not a failing test: the per-block writes are what the
numbers below were paying for.

format bench, soldr cargo bench -p obs-c-oracle --bench port_comparison,
branch and master run back to back on the same host (Ryzen 7 3700X, GCC
15.2.0, four worker checkouts resident), medians:

case master Rust branch Rust speedup C master C branch
format/uyvx_to_i420/1080p 2.050 ms 1.512 ms 1.36x 0.892 ms 0.915 ms
format/uyvx_to_nv12/1080p 1.649 ms 1.403 ms 1.18x 0.752 ms 0.787 ms
format/uyvx_to_i444/1080p 1.943 ms 1.686 ms 1.15x 1.189 ms 1.131 ms

The C column of each pair moves ≤ 5 %, so the Rust deltas are not host drift
beyond that. Against the -O3 oracle these cases are still ~1.5-1.9x, so this
Refs #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 on
top of current master and on top of this row-write change, and measured both
ways (format/uyvx_to_*/1080p, same host):

  • SIMD kernel on master's per-block writes: i420 2.18 ms vs master 1.89 ms,
    nv12 3.70 ms vs master 1.66 ms.
  • SIMD kernel on this PR's row writes: i420 1.89 ms (vs 1.51 scalar),
    nv12 3.70 ms (vs 1.40 scalar).

Returning a Block { y, u, v: [[u8; 4]; 2] } from the kernel costs more than
the 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 next
step 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).

@zackees

zackees commented Oct 31, 2026

Copy link
Copy Markdown
Member Author

Ready and on auto-merge. Local checks that ran on this branch: ./lint (all lanes green except the load-sensitive ci/test_tier2_serial_cpus.py timing assertion, which passes alone) and OBS_PARITY_CASES=reduced soldr cargo test -p obs-media-io --lib tests::video::format_conversion (32 passed). There is no Local-Gate: stamp: the lane set is ~1 h on this host and PR CI is the gate, so this PR is the first full run. Fast Gate is green; the Rust Tier 2 lane is the one to watch.

@zackees
zackees added this pull request to the merge queue Oct 31, 2026
Merged via the queue into master with commit 538e920 Oct 31, 2026
41 checks passed
@zackees
zackees deleted the perf/3004-uyvx-row-writes branch October 31, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant