Repository navigation
obs-codec: AV1 output shims write straight into their bmalloc buffers (Fixes #1304) - #1414
Merged
Merged
Conversation
…rust#1304) RED: 0/3. The shims make Rust heap allocations before they copy into bmalloc: obs_extract_av1_headers 7 for a 256-byte keyframe packet (two growing Vecs) and 2 without header OBUs, metadata_obu and metadata_obu_itu_t35 1 each (an exact-size Vec). obs-av1.c allocates only the outputs. Counting Rust heap allocations on the calling thread is deterministic, unlike a time bound (as for obs-rust#1296). Benchmarks before the fix (Apple M1 Max, record.py options, av1/ only, 5 paired passes; median Rust/C and paired range): av1/extract/16384 1.195x (1.182-1.227) av1/extract/256 1.079x (0.979-1.080) av1/metadata 1.725x (1.676-1.734) av1/metadata_itu_t35 1.719x (1.689-1.741) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Fixes obs-rust#1304) GREEN: 3/3 allocation tests, 14/14 AV1 tests (parity proptests against the obs-av1.c oracle unchanged), 78/78 obs-tests-codec, clippy -D warnings, bench fixture checks. The safe core now gives slices instead of owned buffers: - av1::header_obus(data) yields the sequence header and metadata OBUs as slices of `data`. The packet output is all of `data` (the OBU walk covers every byte), so obs_extract_av1_headers copies it once. - av1::metadata_obu_prefix returns the header byte, leb128 size and type in a 12-byte stack buffer; the shim copies prefix, payload and the trailing bits into one bmalloc buffer. - packet::bmalloc_concat_iter fills one bmalloc buffer from an iterator of slices and panics instead of writing past it when the parts do not add up to the length. extract_headers and metadata_obu keep their Vec API for the tests. Benchmarks (Apple M1 Max, record.py options, av1/ only, 5 paired passes, same load as the RED run; median Rust/C and paired range): av1/extract/16384 1.195x -> 0.662x (0.647-0.662) av1/extract/256 1.079x -> 0.486x (0.483-0.491) av1/metadata 1.725x -> 0.949x (0.908-0.958) av1/metadata_itu_t35 1.719x -> 0.948x (0.915-0.952) av1/keyframe/* unchanged (1.026-1.033x, obs-rust#1303) Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 18, 2026
This was referenced Oct 18, 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.
Fixes #1304
What and why
The AV1 C ABI shims made Rust heap allocations before they copied into
bmalloc.obs_extract_av1_headersgrew twoVecs (7 allocations for a 256-byte keyframe packet) and then copied each one.metadata_obuandmetadata_obu_itu_t35built an exact-sizeVecand copied it.obs-av1.callocates only the outputs. This madeav1/extractandav1/metadata1.26x to 1.51x slower than C in #1295.The safe core now gives slices, and the shims copy them straight into one
bmallocbuffer per output:av1::header_obus(data)yields the sequence header and metadata OBUs as slices ofdata. The packet output is all ofdata: the OBU walk starts at 0, every OBU is at least one byte and the last one is cut to the end of the buffer, so the OBUs cover every byte.av1::metadata_obu_prefixreturns the header byte, the leb128 size and the type in a 12-byte stack buffer. The shim copies prefix, payload and the trailing bits into one buffer.packet::bmalloc_concat_iterfills onebmallocbuffer from an iterator of slices. It panics instead of writing past the buffer when the parts do not add up to the length.extract_headersandmetadata_obukeep theirVecAPI for the tests. No change to the C ABI or to any output byte: header duplication, metadata type, leb128 size, trailing bits, NULL with size 0 for empty outputs andbmalloc/bfreeownership stay the same.RED → GREEN
rust/obs-codec/tests/codec/av1_alloc.rscounts Rust heap allocations on the calling thread (counting global allocator, as indstr_alloc.rsfor bug: dstr: safe formatting is 6.6–58.2× slower than C #1296);bmallocuses the C allocator, so the outputs themselves are not counted. 0/3 pass: extract 7 allocations (256-byte packet) and 2 (no header OBUs), metadata 1 and 1.obs-av1.coracle; 78/78obs-tests-codec; clippy-D warnings;cargo bench ... -- --testfixture checks. Tier 2 (C tests againstlibobs-with-rust) runs in PR CI.record.pyoptions (--sample-size 30 --warm-up-time 0.1 --measurement-time 0.4 --nresamples 10000), only theav1/cases, 5 paired passes before and after, same host (Apple M1 Max) and load. Median Rust/C and paired range:av1/extract/16384av1/extract/256av1/metadataav1/metadata_itu_t35av1/keyframe/16384(not changed, #1303)av1/keyframe/256(not changed, #1303)All four cases of #1304 are now below the 1.10 bound. Extraction is faster than C because C grows its
DARRAYs OBU by OBU, while the packet is now one copy. The unchanged keyframe cases show that the two runs are comparable.Checklist
masterdocs/features.mdis added or updated (not applicable: no user-visible change; the Rust libobs is not shipped by default)-W..., ratchets): not applicable🤖 Generated with Claude Code