forge
Explore
Log in

Don't you dare go Hollow

revert "perf(av1): the DPB shares one Arc per picture instead of copying it per slot"

Browse files at this commit

173712b7297f57d0e00d9b795e0bd95308fa217dAhmet Kaan GümüşParent: bf70705
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.rsmodified+7 -14
@@ -281,11 +281,7 @@ pub fn decode_stream_with(
281 // luma-only (chroma coincidentally shares this fixture's flat regions)281 // luma-only (chroma coincidentally shares this fixture's flat regions)
282 // and small-magnitude (the two pictures mostly agree), which is exactly282 // and small-magnitude (the two pictures mostly agree), which is exactly
283 // what made it look like a rounding bug rather than a wrong reference.283 // what made it look like a rounding bug rather than a wrong reference.
284- // lane-perf9: the DPB holds each picture behind an `Arc`, so a frame whose284+ let mut ref_slots: [Option<Picture>; NUM_REF_FRAMES] = std::array::from_fn(|_| None);
285- // `refresh_frame_flags` names several slots (a key frame names all eight)
286- // stores eight pointers instead of eight ~25 MB 4K picture copies.
287- let mut ref_slots: [Option<std::sync::Arc<Picture>>; NUM_REF_FRAMES] =
288- std::array::from_fn(|_| None);
289 // lane-av1tmvp: each of the 8 reference slots' own saved temporal motion285 // lane-av1tmvp: each of the 8 reference slots' own saved temporal motion
290 // field (spec 7.9's per-frame `MotionFieldMvs` storage, libaom286 // field (spec 7.9's per-frame `MotionFieldMvs` storage, libaom
291 // `cur_frame->mvs`) plus the `OrderHint` the picture in that slot was287 // `cur_frame->mvs`) plus the `OrderHint` the picture in that slot was
@@ -375,7 +371,7 @@ pub fn decode_stream_with(
375 bit_depth as u32,371 bit_depth as u32,
376 )372 )
377 } else {373 } else {
378- (*picture).clone()374+ picture
379 };375 };
380 sink(&output, pictures_decoded, true)?;376 sink(&output, pictures_decoded, true)?;
381 pictures_shown += 1;377 pictures_shown += 1;
@@ -855,7 +851,7 @@ pub fn decode_stream_with(
855 } else {851 } else {
856 ref_slots852 ref_slots
857 .get(header.ref_frame_idx[ref_frame - 1] as usize)853 .get(header.ref_frame_idx[ref_frame - 1] as usize)
858- .and_then(|slot| slot.as_deref())854+ .and_then(Option::as_ref)
859 }855 }
860 });856 });
861 // spec 7.9's own driver, `av1_setup_motion_field`: only run when857 // spec 7.9's own driver, `av1_setup_motion_field`: only run when
@@ -927,9 +923,6 @@ pub fn decode_stream_with(
927 )?;923 )?;
928 (picture, end_cdfs, motion_field)924 (picture, end_cdfs, motion_field)
929 };925 };
930- // lane-perf9: one allocation per decoded frame, then every reference
931- // slot this frame refreshes (and the sink) shares it.
932- let picture = std::sync::Arc::new(picture);
933 // lane-lr r4: the Wiener/self-guided pixel filters are wired926 // lane-lr r4: the Wiener/self-guided pixel filters are wired
934 // (`decode.rs::apply_loop_restoration`) -- no more refusal here,927 // (`decode.rs::apply_loop_restoration`) -- no more refusal here,
935 // `uses_lr` frames now decode all the way to pixels.928 // `uses_lr` frames now decode all the way to pixels.
@@ -1036,16 +1029,16 @@ pub fn decode_stream_with(
1036 let mc_identity = parser1029 let mc_identity = parser
1037 .sequence_header()1030 .sequence_header()
1038 .is_some_and(|seq| seq.color_config.matrix_coefficients == 0);1031 .is_some_and(|seq| seq.color_config.matrix_coefficients == 0);
1039- Some(crate::film_grain::apply_grain(1032+ crate::film_grain::apply_grain(
1040 &picture,1033 &picture,
1041 &header.film_grain,1034 &header.film_grain,
1042 mc_identity,1035 mc_identity,
1043 bit_depth as u32,1036 bit_depth as u32,
1044- ))1037+ )
1045 } else {1038 } else {
1046- None1039+ picture
1047 };1040 };
1048- sink(output.as_ref().unwrap_or(&picture), pictures_decoded - 1, true)?;1041+ sink(&output, pictures_decoded - 1, true)?;
1049 pictures_shown += 1;1042 pictures_shown += 1;
1050 } else {1043 } else {
1051 // Hidden (alt-ref/forward-key) frames never reach1044 // Hidden (alt-ref/forward-key) frames never reach