From 173712b7297f57d0e00d9b795e0bd95308fa217d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 4 Sep 2026 20:57:57 +0300 Subject: [PATCH] revert "perf(av1): the DPB shares one Arc per picture instead of copying it per slot" The wall-clock pairs that commit shipped (38.59 s -> 37.62 s) were noise: at +-2% run-to-run on this box three pairs cannot resolve a 1% effect. Measured again with `perf stat` (near-deterministic for this decoder) over six interleaved runs each, the Arc form retires 0.15 G fewer instructions -- the picture copies really do disappear, and page faults drop 401 k -> 142 k -- and still burns ~1% MORE cycles on seg4k: 188.4 G median (main) vs 190.7 G. The eight stable per-slot buffers the copies recycle are cheaper to walk than the one buffer per decoded frame the shared form allocates and frees. `perf stat -e cycles:u,instructions:u` on seg4k, alternating binaries, is the instrument the rest of this lane used; wall clock is not. --- crates/ec-av1/src/stream.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 6c7bed28..9e70e600 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -281,11 +281,7 @@ pub fn decode_stream_with( // luma-only (chroma coincidentally shares this fixture's flat regions) // and small-magnitude (the two pictures mostly agree), which is exactly // what made it look like a rounding bug rather than a wrong reference. - // lane-perf9: the DPB holds each picture behind an `Arc`, so a frame whose - // `refresh_frame_flags` names several slots (a key frame names all eight) - // stores eight pointers instead of eight ~25 MB 4K picture copies. - let mut ref_slots: [Option>; NUM_REF_FRAMES] = - std::array::from_fn(|_| None); + let mut ref_slots: [Option; NUM_REF_FRAMES] = std::array::from_fn(|_| None); // lane-av1tmvp: each of the 8 reference slots' own saved temporal motion // field (spec 7.9's per-frame `MotionFieldMvs` storage, libaom // `cur_frame->mvs`) plus the `OrderHint` the picture in that slot was @@ -375,7 +371,7 @@ pub fn decode_stream_with( bit_depth as u32, ) } else { - (*picture).clone() + picture }; sink(&output, pictures_decoded, true)?; pictures_shown += 1; @@ -855,7 +851,7 @@ pub fn decode_stream_with( } else { ref_slots .get(header.ref_frame_idx[ref_frame - 1] as usize) - .and_then(|slot| slot.as_deref()) + .and_then(Option::as_ref) } }); // spec 7.9's own driver, `av1_setup_motion_field`: only run when @@ -927,9 +923,6 @@ pub fn decode_stream_with( )?; (picture, end_cdfs, motion_field) }; - // lane-perf9: one allocation per decoded frame, then every reference - // slot this frame refreshes (and the sink) shares it. - let picture = std::sync::Arc::new(picture); // lane-lr r4: the Wiener/self-guided pixel filters are wired // (`decode.rs::apply_loop_restoration`) -- no more refusal here, // `uses_lr` frames now decode all the way to pixels. @@ -1036,16 +1029,16 @@ pub fn decode_stream_with( let mc_identity = parser .sequence_header() .is_some_and(|seq| seq.color_config.matrix_coefficients == 0); - Some(crate::film_grain::apply_grain( + crate::film_grain::apply_grain( &picture, &header.film_grain, mc_identity, bit_depth as u32, - )) + ) } else { - None + picture }; - sink(output.as_ref().unwrap_or(&picture), pictures_decoded - 1, true)?; + sink(&output, pictures_decoded - 1, true)?; pictures_shown += 1; } else { // Hidden (alt-ref/forward-key) frames never reach