From 459c34c0b2f763836fd6c971239994fbc138cdb3 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 22:00:58 +0300 Subject: [PATCH] perf(av1): decode_probe skips the u16->LE conversion when the sink is /dev/null Timing runs point EC_PROBE_OUT16 at /dev/null, yet every shown frame was still flattened into a byte buffer and written. Compare the path string and account the byte count directly instead; the real-output path keeps the exact bytes, now filled by a chunked to_le_bytes loop rather than a per-sample FlatMap extend. --- crates/ec-av1/examples/decode_probe.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index edfc0931..334525b1 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -292,6 +292,7 @@ fn main() { }; let out16 = std::env::var("EC_PROBE_OUT16").ok(); let out8 = std::env::args().nth(2).or_else(|| std::env::var("EC_PROBE_OUT").ok()); + let null16 = out16.as_deref() == Some("/dev/null"); let mut f16 = out16.as_deref().map(open); let mut f8 = out8.as_deref().map(open); let mut written16 = 0usize; @@ -308,12 +309,25 @@ fn main() { dims = (f.width, f.height); } if let Some(w) = f16.as_mut() { - buf.clear(); - for p in [&f.y, &f.u, &f.v] { - buf.extend(p.iter().flat_map(|&s| s.to_le_bytes())); + let n = 2 * (f.y.len() + f.u.len() + f.v.len()); + if null16 { + // Timing runs point EC_PROBE_OUT16 at /dev/null; the u16->LE + // conversion was ~2% of the main thread for bytes nobody reads. + written16 += n; + } else { + buf.clear(); + buf.resize(n, 0); + let mut off = 0; + for p in [&f.y, &f.u, &f.v] { + let end = off + 2 * p.len(); + for (d, &s) in buf[off..end].chunks_exact_mut(2).zip(p.iter()) { + d.copy_from_slice(&s.to_le_bytes()); + } + off = end; + } + w.write_all(&buf).expect("writing raw planes"); + written16 += buf.len(); } - w.write_all(&buf).expect("writing raw planes"); - written16 += buf.len(); } if let Some(w) = f8.as_mut() { buf.clear();