lane-av1stacksweep: sweep the by-value class, gate it on a measured budget, box Encoded and Av1Encoder::carried_cdfs
THE CLASS, NAMED: a large struct returned BY VALUE from a public constructor is
a stack cost paid by the CALLER, and the constructors NEST, so one value's size
is the multiplier and the chain length is the other factor. Av1Encoder was
139960 bytes by value and aborted on libtest's 2 MiB thread, twice, on
unmodified main. lane-av1enchang fixed that ONE struct and gated that ONE
constructor. Nobody swept the class, and nothing said which types were checked.
THE FIX, same shape as lane-av1enchang (99750756) which boxed DpbSlot::cdfs.
Boxing the per-slot CdfSnapshot left two more copies of the same 15232-byte
table sitting inline, and nobody had measured either:
Encoded::start_cdfs / next_cdfs CdfSnapshot -> Box<CdfSnapshot>
Av1Encoder::carried_cdfs Option<CdfSnapshot> -> Option<Box<..>>
Encoded 30728 -> 280 bytes (99.2% was those two fields)
Av1Encoder 18168 -> 2944 bytes (15232 of it was carried_cdfs)
The VALUES are untouched, so the bitstream is byte-identical. The two fields
and CdfSnapshot itself are pub(crate), so this is NOT a breaking API change:
grep over crates/ finds no reader of either field outside ec-av1, and Encoded's
public fields (stream, reconstruction, modes, inter_block_share) keep their
types. refresh() now hands the already-boxed snapshot to the DPB slot instead
of boxing a second time.
THE SWEEP, crates/ec-av1/src/stack_budget.rs, 8 tests, 0.10s:
the_measured_inventory_is_accurate 21 by-value types, measured, and the
table PRINTS sorted so one command
reproduces the whole inventory
every_by_value_type_fits_the_stack_budget the bound, asserted BY NAME
the_deepest_by_value_constructors_fit_on_a_tight_stack
capability: both deepest public
chains really constructed on a 1 MiB
thread, so a regression ABORTS
every_by_value_public_return_is_in_the_inventory
source scan over 38 modules; a new
by-value pub return reds unmeasured
every_by_value_module_is_scanned the scan's file list derived from
lib.rs -- it immediately named 15
modules the scan was not reading
the_inventory_scan_is_not_vacuous control; it caught a live bug in the
matcher (Result<T, E> parsed as the
name "T, E")
the_crate_private_cdf_tables_stay_behind_a_box
pins the four Box<> declarations
test_threads_get_the_stack_they_are_given
the 2101248-byte floor the bound is
derived from, read from /proc, not
assumed
THE BOUND: 8192 bytes, derived from measurement at BOTH ends and asserted at
both ends. Bounded quantity is what a caller can owe: 2101248 bytes (measured,
/proc/self/task/<tid>/maps) x a 4-deep public chain x an eighth-of-the-stack
share, with the worst public return at 2944 B = 35.9% of budget. The test
asserts DEEPEST_PUBLIC_CHAIN * worst * 8 <= 2 MiB so the derivation cannot rot.
Catches: pre-fix Av1Encoder 17.1x over, Encoded-before-this-lane 3.75x over,
and ec_opus::Encoder (measured in a sibling crate by the same sweep) 10.6x
over. The crate-private Cdfs/CdfSnapshot are measured and listed but NOT
bounded, because no pub fn returns them -- bounding them would calibrate the
number to something no caller can reach.
MUTATION-PROVEN, both reverted and both re-run after the refactor:
unbox DpbSlot::cdfs (revert 99750756) -> "Av1Encoder is 139960 bytes, over
the 8192-byte by-value stack budget (17.09x)" by name, plus SIGABRT
grow Encoded by a 64 KiB inline payload -> "Encoded is 96264 bytes, over
the ... budget (11.75x)" by name, plus SIGABRT
THE CAP: the 64 MiB RUST_MIN_STACK in .cargo/config.toml was protecting
exactly this and no longer needs to. One debug test genuinely needed >2 MiB --
encoder::tests::the_facade_codes_the_same_bytes_as_encode_sequence, 2097152
red / 3145728 green -- and THIS COMMIT FIXES IT: it now passes at 2 MiB. A
799-test per-test sweep at RUST_MIN_STACK=2097152 is in the lane report. I am
not editing .cargo/config.toml, as chartered; the report carries the exact
replacement comment and states that its current wording is wrong (the state it
blames is Vec/VecDeque, i.e. heap; the only fixed-size stack local in the
encoder path is a `const` in film_grain.rs).
Measured deepest chain: 786432 bytes before, 475136 after (1 MiB gate is now
2.2x margin, was 1.33x). The ~470 KB that remains is the encode search's own
frames.
No decode.rs. No bitstream change. No .cargo/config.toml edit. No rustfmt.
Lane report: lanes/av1stacksweep.report.md.