Skip to content

perf(media-io): borrow each UYVX block instead of copying it (#3004) - #3134

Merged
zackees merged 1 commit into
masterfrom
fix/3004-uyvx-block-borrow
Oct 31, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3004-uyvx-block-borrow

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 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. This borrows the block with Source::bytes (the method #3111 added for exactly this cost on the decompress half) and narrows channel/average to &[u8].

No arithmetic, loop bound, u32 wrapping, 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, master 81ac46b16 vs this branch, min of 5 paired runs (Ryzen 7 3700X, GCC 15.2.0, host carrying four worker checkouts):

case master Rust branch Rust speedup C master C branch
format/uyvx_to_i420/1080p 2.31 ms 2.12 ms 1.09x 0.643 ms 0.690 ms
format/uyvx_to_i444/1080p 2.53 ms 2.14 ms 1.18x 1.043 ms 1.166 ms
format/uyvx_to_nv12/1080p 2.38 ms 1.88 ms 1.27x 0.553 ms 0.564 ms

The C column of the same runs stays within 7 %, so the Rust deltas are not host drift; the rust-over-C ratio in record.py is not used here because the oracle on master is still the bench profile's -O3 (the shipped -O2 clamp 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 on uyvx_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).

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
zackees marked this pull request as ready for review October 31, 2026 08:24
@zackees
zackees added this pull request to the merge queue Oct 31, 2026
@zackees

zackees commented Oct 31, 2026

Copy link
Copy Markdown
Member Author

Handed off to the coordinator.

CI Gate ✅ is green on 74e1b8fae (Fast Gate 4m08s, Tier 2 Linux tests ON/OFF plus both serial halves, Format, Validate Data; the macOS/Windows app lanes are path-skipped). ./lint was ok locally (150.7 s) and the format-conversion module's 32 tests — including the C-oracle parity proptests — pass with OBS_PARITY_CASES=reduced.

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.

Merged via the queue into master with commit 3e17f5d Oct 31, 2026
41 checks passed
@zackees
zackees deleted the fix/3004-uyvx-block-borrow branch October 31, 2026 08:32
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