From 4231093b8dff91a428c87850f85002b5721fbe3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 5 Sep 2026 23:21:56 +0300 Subject: [PATCH] perf(av1): two-stage reference promises default OFF -- byte-exact, but the overlap is too short to pay Measured, not assumed. An inter tile parses 4.2% of its own length before its first `ref_planes` call (seg4k, 272 frames, 16/4/2, instrumented first-touch timer) because the 8x8-leaf, OBMC and sub-8x8-piece predictions build INLINE on the parse thread -- only the 16x16-and-bigger blocks go to a recon worker. So a consumer overlaps ~3 ms of its parse plus its 1.2 ms setup with a producer tail of ~7 ms per chain frame. The chain report shows exactly that: the segments now sum to 108% of the chain instead of 101% (the tail IS overlapped), while the chain itself is unchanged (5621.7 ms vs 5547.2 ms) and the wall does not move (seg4k at (16,4,2): base 5143/5337/5350 ms vs 5244/5738 ms; at (6,1,1): base 10498/10635/11232 vs 10128/10309/11747). The machinery stays -- it is byte-exact on all four gate configs and the six film cuts, and it is the half of the lever that is hard to build. It pays once the 8x8-leaf/OBMC/sub-8x8 predictions are deferred to the recon workers too; until then `EC_AV1_TWO_STAGE=1` enables it and the default publishes a frame's meta after its filters, as before. --- crates/ec-av1/src/stream.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 774fd9a6..35aa354c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -1006,13 +1006,19 @@ pub fn decode_stream_with_threads( decode_idx, shown_idx, dump.as_deref(), - // lane-twostage kill switch: `EC_AV1_TWO_STAGE=0` - // publishes a frame's meta where it always was - // (after its filters), for bisecting a mismatch. + // lane-twostage is OFF by default: it is byte-exact + // and the chain shows the producer tail overlapped, + // but it does not move the wall (the consumer parses + // only 4.2% of its tile before its first reference + // pixel read, which is shorter than the tail it + // hides). `EC_AV1_TWO_STAGE=1` publishes a frame's + // meta at its tile boundary instead of after its + // filters; it pays only once the 8x8-leaf, OBMC and + // sub-8x8-piece predictions are deferred to the recon + // workers as well. crate::envflags::var("EC_AV1_TWO_STAGE") - .is_ok_and(|v| v == "0") - .then_some(()) - .map_or(Some(&stage1 as &dyn Fn(_, _, _, _)), |()| None), + .is_ok_and(|v| v == "1") + .then_some(&stage1 as &dyn Fn(_, _, _, _)), )?; // Publish before grain synthesis: every frame waiting on // this slot can start the moment the clean picture exists