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