forge
Explore
Log in

Don't you dare go Hollow

Decode_probe skips the u16->LE conversion when the sink is /dev/null

Browse files at this commit

459c34c0b2f763836fd6c971239994fbc138cdb3Ahmet Kaan GümüşParent: a263e1e
  • perf
    • decode_probe skips the u16->LE conversion when the sink is /dev/null
Show full message
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.rsmodified+19 -5
@@ -292,6 +292,7 @@ fn main() {
292 };292 };
293 let out16 = std::env::var("EC_PROBE_OUT16").ok();293 let out16 = std::env::var("EC_PROBE_OUT16").ok();
294 let out8 = std::env::args().nth(2).or_else(|| std::env::var("EC_PROBE_OUT").ok());294 let out8 = std::env::args().nth(2).or_else(|| std::env::var("EC_PROBE_OUT").ok());
295+ let null16 = out16.as_deref() == Some("/dev/null");
295 let mut f16 = out16.as_deref().map(open);296 let mut f16 = out16.as_deref().map(open);
296 let mut f8 = out8.as_deref().map(open);297 let mut f8 = out8.as_deref().map(open);
297 let mut written16 = 0usize;298 let mut written16 = 0usize;
@@ -308,12 +309,25 @@ fn main() {
308 dims = (f.width, f.height);309 dims = (f.width, f.height);
309 }310 }
310 if let Some(w) = f16.as_mut() {311 if let Some(w) = f16.as_mut() {
311- buf.clear();312+ let n = 2 * (f.y.len() + f.u.len() + f.v.len());
312- for p in [&f.y, &f.u, &f.v] {313+ if null16 {
313- buf.extend(p.iter().flat_map(|&s| s.to_le_bytes()));314+ // Timing runs point EC_PROBE_OUT16 at /dev/null; the u16->LE
315+ // conversion was ~2% of the main thread for bytes nobody reads.
316+ written16 += n;
317+ } else {
318+ buf.clear();
319+ buf.resize(n, 0);
320+ let mut off = 0;
321+ for p in [&f.y, &f.u, &f.v] {
322+ let end = off + 2 * p.len();
323+ for (d, &s) in buf[off..end].chunks_exact_mut(2).zip(p.iter()) {
324+ d.copy_from_slice(&s.to_le_bytes());
325+ }
326+ off = end;
327+ }
328+ w.write_all(&buf).expect("writing raw planes");
329+ written16 += buf.len();
314 }330 }
315- w.write_all(&buf).expect("writing raw planes");
316- written16 += buf.len();
317 }331 }
318 if let Some(w) = f8.as_mut() {332 if let Some(w) = f8.as_mut() {
319 buf.clear();333 buf.clear();