forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on mainFiltered to crates/ec-av1/examples/alloc_timing.rsClear filter

2026-10-01

ec-av1: pick the plane-allocation closure with a number, and ship the zeroed oneAhmet Kaan Gümüş · fd10b92
ec-av1: pick the plane-allocation closure with a number, and ship the zeroed one

fresh_plane handed the decoder an uninitialised buffer and the SAFETY comment
resting on "every sample is written before it is read". That premise was
withdrawn by lane/unwritten-dep's own measurement (224 caller-visible chroma
samples on 440_request_is_422) and the comment was left standing anyway, with
two closures filed and neither chosen: zero the allocation, or instrument the
reads. Choosing between a perf cost and a new instrument is not a measurement
lane's call, so this is that lane.

Measured, one stream at a time, one binary: EC_AV1_PLANE_ALLOC is an env arm
inside the crate rather than a build flag, because three separate builds cannot
make the comparison fair -- recycled-arena state, page-cache state and code
layout all differ between them. Medians of 11 interleaved runs, examples/
alloc_timing.rs (new) timing decode_stream_with and reading minflt around it:

  3840x2160 4:2:0 96f   uninit 6900.963 ms | fill +0.83% | zeroed +0.80%
  3840x2160 4:2:2 48f   uninit 4709.657 ms | fill +0.86% | zeroed +0.81%
  1920x1080 4:2:0 96f   uninit 1768.411 ms | fill -1.87% | zeroed -1.63%

The 4K deltas are ~6 sigma against a 7-10 ms run-to-run spread. alloc_zeroed is
NOT the free zero-page lunch its name suggests: zeroed and fill land within
0.03% of each other at every size, because glibc memsets a recycled arena block
just the same. Output hashes are identical across all three arms on every
stream. The 1080p sign flip is reproducible and unexplained; it is reported as
a number, not a story.

The read census, which is what the decision actually rests on. Three regions of
the allocation can hold a sample no block wrote, and the old census only
scanned one of them:

  1. the padded tail outside true_width x true_height -- unwritten by
     construction; 4,676,128 of 22,787,296 scanned tail samples over all 127
     fixtures, on 38 of them. The comment claimed "no decoder ever reads" it;
     that was self-certifying, so the tail is now counted like any other
     region.
  2. the true extent, where the withdrawn 224-sample case sat -- 0 unwritten of
     1,466,581,280 scanned. The witness is refused on main.
  3. pix_write's `prev` argument, which reads the destination sample before
     overwriting it on every store. Neither instrument can see it (the value
     never reaches a branch or a syscall, so a DEBUG build under memcheck on
     the uninit arm still reports 0 errors) and no hash moves -- but it is a
     read of initial content nonetheless.

Reads were measured two independent ways and both say zero, over the whole
corpus: valgrind memcheck on every fixture under both the uninit and the zeroed
arm (254 runs, 0 uninitialised-value errors, identical signature sets), and
differential poisoning -- 126/126 committed fixtures byte-identical under
0xDEAD, 0xBEEF and the zeroed closure, the 127th being the refused witness.
The memcheck instrument is shown live by mutation: a temporary env-gated read
of the plane's last slot makes the same binary report 12 errors from 4
contexts. Reverted.

So the shipped closure is PlaneAlloc::Zeroed (vec![0u16; n]). The unsafe is now
reachable only from the census arms, its SAFETY comment names the three regions
with their measured counts instead of a premise, and the refusal that closes
region 2 is stated as a refusal rather than a proof -- a hostile file picks its
own subsize values, and that check lives in the tile walk, not at the
allocation.

New gate stream::tests::the_frame_does_not_depend_on_the_plane_buffers_initial
_content: four child processes (two impossible poisons, sentinel-off+uninit,
sentinel-off+zeroed) over ten fixtures must agree on one FNV-1a hash each, with
a synthetic one-sample control first so the equalities cannot be vacuous and a
frames>0 assertion so two children that decoded nothing cannot agree. 4.6 s.

Not in this commit: a pooled plane buffer would make the closure ~free (take the
three buffers from a thread-local pool, zero each once at creation, return on
drop) but it changes PlaneBuf's ownership, which the wavefront workers hold.
Recorded in the report rather than done.

Full table, reader map, census and non-vacuity evidence: lanes/av1uballoc.report.md