From d9a2cb4f2cde9becf171cc8b472d1be6c09b14d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 3 Sep 2026 04:26:51 +0300 Subject: [PATCH] docs(av1): lane-streamsink r1 report -- peak RSS 6.28 GB -> 0.44 GB on a 4K 10-bit window, flat in segment length Also ships the FIFO census runner used to verify it: our decoder streams frames into a FIFO, the comparer reads one frame per side at a time. --- lanes/streamsink-r1-run_film_fifo.sh | 52 ++++++++++++++++++++++++++++ lanes/streamsink-r1.report.md | 50 ++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100755 lanes/streamsink-r1-run_film_fifo.sh create mode 100644 lanes/streamsink-r1.report.md diff --git a/lanes/streamsink-r1-run_film_fifo.sh b/lanes/streamsink-r1-run_film_fifo.sh new file mode 100755 index 00000000..b4d6307c --- /dev/null +++ b/lanes/streamsink-r1-run_film_fifo.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# lane-streamsink r1: same census as run_film.sh, but our decoder streams its +# frames into a FIFO (ec_av1::stream::decode_stream_with, one frame written the +# moment it completes) and cmp2.py reads one frame from that FIFO and one from +# ffmpeg's stdout at a time. Neither side ever holds more than a frame, so the +# segment length no longer bounds memory -- peak RSS of the decoder is ~0.44 GB +# on a 4K 10-bit window regardless of how long the window is. +# usage: run_film_fifo.sh [probe] +set -u +S="$(cd "$(dirname "$0")" && pwd)" +NAME="$1"; FILM="$2"; W="$3"; H="$4"; SEG="$5" +PROBE="${6:-$HOME/.cache/cargo-target-streamsink/release/examples/decode_probe}" +T=$HOME/.cache/fullfilm-fifo/$NAME +rm -rf "$T"; mkdir -p "$T" +STATE=$T/state.json +DUR=$(ffprobe -v error -show_entries format=duration -of default=nw=1:nk=1 "$FILM" | cut -d. -f1) +echo "START name=$NAME res=${W}x${H} depth=10 codec=av1 duration_s=$DUR seg_s=$SEG mode=fifo" +T0=$(date +%s) +s=0 +while [ "$s" -lt "$DUR" ]; do + seg=$T/seg.obu; fifo=$T/ours.fifo + rm -f "$seg" "$fifo" + ffmpeg -nostdin -loglevel error -ss "$s" -t "$SEG" -i "$FILM" -map 0:v:0 -c:v copy -an -f obu "$seg" -y 2>/dev/null + if [ ! -s "$seg" ]; then echo "t=${s}s NO-SEGMENT"; s=$((s+SEG)); continue; fi + mkfifo "$fifo" + base=$(python3 -c 'import json,sys,os +p=sys.argv[1] +print(json.load(open(p))["compared"] if os.path.exists(p) else 0)' "$STATE") + EC_PROBE_OUT16="$fifo" timeout 7200 "$PROBE" "$seg" > "$T/probe.log" 2>&1 & + probe=$! + line=$(ffmpeg -nostdin -loglevel error -i "$seg" -pix_fmt yuv420p10le -f rawvideo - 2>/dev/null \ + | python3 "$S/cmp2.py" "$fifo" "$W" "$H" "$STATE" "$base") + wait $probe; rc=$? + r=$(grep -E '^REFUSED|^OK|panick|rror' "$T/probe.log" | head -1) + [ $rc -ge 128 ] && r="KILLED(rc=$rc)" + [ -z "$r" ] && r="NO-MATCH-LINE(rc=$rc)" + now=$(date +%s); el=$((now-T0)); [ "$el" -lt 1 ] && el=1 + tot=$(python3 -c 'import json,sys,os +p=sys.argv[1] +print(json.load(open(p))["compared"] if os.path.exists(p) else 0)' "$STATE") + fpm=$(python3 -c "print(round($tot*60.0/$el,2))") + printf 't=%ss\t%s\t%b\telapsed_s=%s\tfpm=%s\n' "$s" "$r" "$line" "$el" "$fpm" + rm -f "$seg" "$fifo" + s=$((s+SEG)) +done +now=$(date +%s); el=$((now-T0)); [ "$el" -lt 1 ] && el=1 +python3 -c ' +import json,sys +st=json.load(open(sys.argv[1])); el=int(sys.argv[2]); name=sys.argv[3] +print("FULLFILM name=%s compared=%d differing=%d first_bad=%s first_bad_bytes=%d max_bytes=%d segments=%d elapsed_s=%d fpm=%.2f" + % (name, st["compared"], st["differing"], st["first_bad"] if st["first_bad"] is not None else "-", + st["first_bad_bytes"], st["max_bytes"], st["segments"], el, st["compared"]*60.0/el))' "$STATE" "$el" "$NAME" diff --git a/lanes/streamsink-r1.report.md b/lanes/streamsink-r1.report.md new file mode 100644 index 00000000..2200fc82 --- /dev/null +++ b/lanes/streamsink-r1.report.md @@ -0,0 +1,50 @@ +# lane-streamsink r1 -- streaming decode entry point + +## What changed +- `crates/ec-av1/src/stream.rs:223` -- `decode_stream` is now a thin collecting wrapper; + the decode loop lives in **`decode_stream_with(data, sink)`** (stream.rs:236), + `sink: impl FnMut(&Picture, decode_idx: usize, shown: bool) -> Result<()>`. + Each completed picture is handed to the sink and dropped; only the 8 reference + slots (+ CDF/motion-field/segment-map slots) and the current frame stay alive. + Hidden (`show_frame == 0`) frames are reported with `shown == false` and are not + part of `decode_stream`'s Vec; `show_existing_frame` outputs and shown frames come + with `shown == true` (grain applied, as before). A sink `Err` aborts the decode. +- Same file: the `EC_AV1_DUMP_TABLES` label used `pictures.len()`; it is a shown-output + counter (`pictures_shown`) now, same numbers. `EC_AV1_FINAL_DUMP` / + `EC_AV1_DECODE_ORDER_DUMP` already wrote one frame at a time (one frame-sized buffer). +- `crates/ec-av1/examples/decode_probe.rs:~270` -- decodes through `decode_stream_with` + and writes each shown frame to `EC_PROBE_OUT16` (yuv420p10le) / `EC_PROBE_OUT`|argv[2] + (8-bit) as it completes, into a file **or a FIFO**. The old path collected every + Picture and then built a second full copy of the dump before one `fs::write` -- 2x the + whole segment. OK/REFUSED/`wrote N bytes`/counter lines are unchanged. +- `crates/ec-av1/src/stream.rs` tests: `streaming_decode_matches_the_collecting_one` + (same pictures, same order, one callback per shown frame, monotone decode idx, sink + error aborts after 1 call). +- Runner: `/fullfilm/run_film_fifo.sh` -- our decoder streams into a FIFO, + `cmp2.py` (unchanged) reads one frame from the FIFO and one from ffmpeg per iteration. + +## Peak RSS (4K 10-bit 3840x1608, `systemd-run --scope -p MemoryMax=6G /usr/bin/time -v`, EC_PROBE_OUT16=/dev/null) +| stream | old (collect + 2nd copy) | new (streaming) | +|---|---|---| +| 8 s window, 384 shown frames | **6,280,804 kB (6.28 GB, at the cap)** | **436,404 kB (0.44 GB)** | +| 32 s window, 960 shown frames | not run (old scales linearly; 20+ GiB) | **437,860 kB (0.44 GB)** | + +EVIDENCE: ~/.cache/streamsink-tmp/h8.obu, rss32.log | `/usr/bin/time -v` on the old and new decode_probe over an 8 s and a 32 s 4K 10-bit window under a 6 GiB scope | peak RSS 6,280,804 kB -> 436,404 kB (8 s); 437,860 kB at 960 frames, i.e. flat in segment length (target <2.5 GB met, 14x under) + +EVIDENCE: ~/.cache/streamsink-tmp/{old,new}.raw | both probes, EC_PROBE_OUT16, on a 48-frame 4K 10-bit cut | `cmp` identical, 889,159,680 bytes both, "OK: 48 frames decoded, 3840x1608" both + +EVIDENCE: /fullfilm/run_film_fifo.sh h8w | FIFO-fed streaming decode vs ffmpeg yuv420p10le, 2 segments of the 4K 10-bit stream | FULLFILM compared=584 differing=0 max_bytes=0 + +## Suite +SUITE: `cargo test -p ec-av1 --lib` (systemd unit, EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1, log +`$HOME/.cache/streamsink-suite.log`) -- **test result: ok. 430 passed; 0 failed; 38 ignored; +0 measured; 0 filtered out; finished in 891.27s**. Includes refusal_inventory (3), +gate_coverage (9), and the named film gates (128sb, hidden_arf, gm small-side, +mv-clamp/frame-edge) -- all ok. + +## Residue +- accepted: `decode_stream` clones each shown picture into its Vec (one extra frame at + peak on the collecting path). Gates are small; the streaming path is the one that matters. +- deferred: the whole-Vec probe path was NOT kept behind an env -- the streaming output is + byte-identical and the printed lines unchanged, so a second path would be dead code + (unblocks: nothing; `git revert` of this commit if a consumer ever needs it).