edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·9b67700·Tahinli·3 days ago·4021 commits
| 1 | # lane/av1uballoc — the plane allocation closure, decided with a number |
| 2 | |
| 3 | Started from base `2d8fa8a4`; **rebased onto `f01e9738` and re-measured there** |
| 4 | (§7). Target: `crates/ec-av1/src/decode.rs`'s `fresh_plane` and the |
| 5 | `unsafe { v.set_len(n) }` behind it. |
| 6 | |
| 7 | **Decision: ship closure (b), `vec![0u16; n]` (`alloc_zeroed`/`calloc`).** It |
| 8 | costs **+0.84%** of decode wall time at 3840x2160 4:2:0 and **+0.81%** at |
| 9 | 3840x2160 4:2:2 (both ~6σ against a 6–10 ms run-to-run spread), and **−1.63%** |
| 10 | at 1920x1080 — it is *faster* there, reproducibly. It removes the `unsafe` |
| 11 | from every build that is not explicitly asking for a census arm. |
| 12 | |
| 13 | **No fixture on current main reaches an uninitialised read.** The reads-before- |
| 14 | write census below found zero, by two independent instruments, over all 128 |
| 15 | committed fixtures. The charter's stop condition did not fire. |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## 0. Two corrections to the charter before the numbers |
| 20 | |
| 21 | * **`EC_AV1_PERF*` does not exist** in this repository — not in `crates/ec-av1`, |
| 22 | not anywhere. The real decode-timing instruments are `EC_AV1_TIMELINE` |
| 23 | (`src/timeline.rs:1-13`, dumped by `stream.rs:1369`, read by |
| 24 | `scripts/av1-timeline-report.py`) and `EC_AV1_WAVE_STATS`. Neither buckets |
| 25 | decode into stages — they bucket a *frame's phases*, and the report script's |
| 26 | own doc says the per-phase sums exceed `wall` by construction, so they must |
| 27 | not be summed. Neither attributes a cost to an allocation, so this lane added |
| 28 | `examples/alloc_timing.rs`, which times the `decode_stream_with` call and |
| 29 | reads `minflt`/`majflt` from `/proc/self/stat` around it. It prints one |
| 30 | machine-readable line per process, which is what makes the interleaved |
| 31 | round-robin below possible. |
| 32 | |
| 33 | The closures are an **env arm inside the crate** (`EC_AV1_PLANE_ALLOC`), not a |
| 34 | build flag, so all three share one binary, one allocator state and one machine. |
| 35 | Three separate builds cannot make this comparison fair — the recycled-arena |
| 36 | state, the page-cache state and the code layout all differ between them. |
| 37 | |
| 38 | --- |
| 39 | |
| 40 | ## 1. The table |
| 41 | |
| 42 | `cargo run -p ec-av1 --release --example alloc_timing -- <stream>`, arms |
| 43 | round-robined across processes so a drift hits every arm equally. Medians of 11 |
| 44 | runs each (`n=11` below). Linux 7.2.7, 12 cores, glibc, default allocator, |
| 45 | single-threaded decode (`EC_AV1_THREADS=1` is the crate default). |
| 46 | |
| 47 | ### 3840x2160 4:2:0, 96 frames |
| 48 | |
| 49 | | arm | median ms | min ms | mean ms | stdev ms | Δ% | minflt | output hash | |
| 50 | |---|---|---|---|---|---|---|---| |
| 51 | | `uninit` — status quo, `set_len` | 6937.728 | 6926.888 | 6939.318 | 7.731 | +0.00 | 280 846 | `c93abb392857618d` | |
| 52 | | `fill` — closure (a), explicit zero-fill | 7001.420 | 6992.227 | 7001.984 | 6.448 | **+0.92** | 215 336 | `c93abb392857618d` | |
| 53 | | `zeroed` — closure (b), `alloc_zeroed` | 6995.727 | 6978.615 | 6995.769 | 10.201 | **+0.84** | 278 704 | `c93abb392857618d` | |
| 54 | |
| 55 | ### 3840x2160 4:2:2, 48 frames |
| 56 | |
| 57 | | arm | median ms | min ms | mean ms | stdev ms | Δ% | minflt | output hash | |
| 58 | |---|---|---|---|---|---|---|---| |
| 59 | | `uninit` | 4709.657 | 4703.387 | 4716.928 | 16.443 | +0.00 | 204 348 | `1c8526888dc2285d` | |
| 60 | | `fill` | 4750.184 | 4741.289 | 4751.697 | 7.264 | **+0.86** | 142 987 | `1c8526888dc2285d` | |
| 61 | | `zeroed` | 4747.944 | 4740.307 | 4749.023 | 7.219 | **+0.81** | 202 410 | `1c8526888dc2285d` | |
| 62 | |
| 63 | ### 1920x1080 4:2:0, 96 frames |
| 64 | |
| 65 | | arm | median ms | min ms | mean ms | stdev ms | Δ% | minflt | output hash | |
| 66 | |---|---|---|---|---|---|---|---| |
| 67 | | `uninit` | 1768.411 | 1767.167 | 1775.918 | 9.964 | +0.00 | 60 023 | `ba5f2444c2b60885` | |
| 68 | | `fill` | 1735.265 | 1731.097 | 1742.735 | 21.224 | **−1.87** | 47 018 | `ba5f2444c2b60885` | |
| 69 | | `zeroed` | 1739.516 | 1733.861 | 1743.644 | 10.109 | **−1.63** | 59 170 | `ba5f2444c2b60885` | |
| 70 | |
| 71 | **Every hash is identical within a stream.** The closure chosen moves not one |
| 72 | output sample. |
| 73 | |
| 74 | ### What the table says, and what it does not |
| 75 | |
| 76 | * **(b) is not the free lunch the arm's name advertises.** `zeroed` and `fill` |
| 77 | land within 0.03 % of each other at every size. glibc hands a *recycled* |
| 78 | arena block back from `calloc` with the same memset an explicit fill does; the |
| 79 | "a page fault per page is the mechanism" story is wrong for a decoder that |
| 80 | frees and re-allocates the same plane every frame. |
| 81 | * **The cost is one extra pass over a buffer the decode immediately overwrites**: |
| 82 | +55 ms over 96 frames of 24.9 MB ≈ 42 GB/s of extra write bandwidth. The |
| 83 | `minflt` column is *not* the story — `fill` faults the fewest pages at 4K |
| 84 | (215 k vs 281 k) and is still the slowest arm, so page-fault count does not |
| 85 | explain the delta. |
| 86 | * **The 1080p sign flip is real and reproducible** (two independent 11-run |
| 87 | rounds: −1.59 %/−1.51 %, then −1.87 %/−1.63 %) and **is not explained here**. |
| 88 | I am reporting the number, not a story for it. It is the one result a |
| 89 | reviewer should re-run before trusting the 4K cost on their own hardware. |
| 90 | |
| 91 | --- |
| 92 | |
| 93 | ## 2. Reads-before-write census — regions × readers × reachability |
| 94 | |
| 95 | ### 2.1 The two regions |
| 96 | |
| 97 | `fresh_plane(n, true_width, true_height, width, height)` hands back `n = |
| 98 | width * height` slots. `width` is `block_grid(mi_cols) * 32` and |
| 99 | `true_width = mi_cols * 4`, so the plane is a **block-aligned coding surface** |
| 100 | with up to 31 px of margin per axis. `true_width`/`true_height` is the decodable |
| 101 | extent. That splits the allocation into two disjoint regions that can hold a |
| 102 | sample no block wrote: |
| 103 | |
| 104 | | # | region | definition | can a reader reach it? | |
| 105 | |---|---|---|---| |
| 106 | | 1 | **padded tail** | everything outside `true_width × true_height`, out to `width × height` | in principle; **not in practice** — see §2.3 | |
| 107 | | 2 | **true extent** | inside `true_width × true_height` that the tile walk skipped | yes — this is where the withdrawn 224-sample demonstration sat | |
| 108 | |
| 109 | The old `census_unwritten` scanned region 2 only, under a doc comment asserting |
| 110 | *"past that is the padded coding surface's invented tail, which no decoder ever |
| 111 | reads"*. That assertion is exactly what an unread tail looks like, so it was |
| 112 | self-certifying. This lane scans both and counts them separately |
| 113 | (`PAD_UNWRITTEN_SAMPLES` / `take_pad_unwritten_samples`), and the comment now |
| 114 | says what was measured. |
| 115 | |
| 116 | ### 2.2 The readers |
| 117 | |
| 118 | Line numbers are `main` = `2d8fa8a4`. |
| 119 | |
| 120 | | reader class | sites | reads the CURRENT frame? | clamps to true extent? | reachable on a current fixture? | |
| 121 | |---|---|---|---|---| |
| 122 | | intra prediction (neighbour edges, above/right/below/left) | `PlaneBuf::above/left/below/right_of`, `decode.rs:22059-22110` (`own_across = x + side.min(true_width - x)`, same down) | yes | **yes**, `saturating_sub(true_width/true_height)` plus `tile_x1/tile_y1` | no | |
| 123 | | intra TX bound checks | `decode.rs:12630, 13007, 15179, 19411, 23202, 23736, 24428, 25031, 39153, 39341` (`if px >= true_width { continue }`) | yes | yes | no | |
| 124 | | CfL (chroma-from-luma) | via the TX store paths above | yes (luma block region) | yes | no | |
| 125 | | IntraBC / intrabc copy | `decode.rs:14451-14527, 15009-15074` | yes (the block's own luma) | yes | no | |
| 126 | | intra-in-inter | `decode.rs:18266-18387, 23062-23095` | yes | yes | no | |
| 127 | | deblock | `apply_deblock`, `decode.rs:33367-33370` (`tw = true_width.min(cw)`) | yes | yes | no | |
| 128 | | CDEF | `cdef_gather(..., true_width, true_height, ...)`, `decode.rs:34397-34484` | yes | yes | no | |
| 129 | | loop restoration | `restoration.rs:1053+`, driven with `true_width`/`true_height` (`decode.rs:35315-35319`) | yes | yes | no | |
| 130 | | superres upscale | `superres.rs:100-240`, over the mi-aligned margin, cropped to `true_width` | yes | yes | no | |
| 131 | | **inter prediction / MC / warp / OBMC / compound** | `decode.rs:40384-40386, 40399-40406, 42757-42761, 44560-44581` (all pass `true_width`/`true_height` of the REFERENCE plane) | **no — a different frame's buffer** | n/a | n/a | |
| 132 | | reference-frame materialisation | the crop at `decode.rs:38480-38548` | copies the true extent only | yes | n/a | |
| 133 | | `pix_write`'s `prev` argument — **the one unconditional read-before-write in the shipped source** | `decode.rs:22073` (fn), called at `22294`, `22450`, `39014`, `39029`, passing `*o` / the slot's own value | yes — reads the destination sample *before* overwriting it | no | **fires on every store, on every fixture — but is not observable.** See §2.5 | |
| 134 | |
| 135 | The load-bearing structural fact: **every current-frame reader clamps to |
| 136 | `true_width`/`true_height`**, which is why region 1 never fires. The 224-sample |
| 137 | defect of `lanes/unwritten-dep.report.md` was in region 2 and needed no |
| 138 | clamp-bypass — it was the tile walk skipping samples, not a reader reaching |
| 139 | past the edge. |
| 140 | |
| 141 | ### 2.3 Region census — measurement |
| 142 | |
| 143 | `EC_AV1_PLANE_SENTINEL=1 decode_probe <fixture>`, summed over all 128 |
| 144 | committed fixtures, both regions, at the **pre-deblock** point |
| 145 | (`census_unwritten`, called at `decode.rs:38139` in |
| 146 | `decode_key_frame_tile_with_cdfs` and `56507` in the inter path — after |
| 147 | `flush_recon`, before `apply_deblock`): |
| 148 | |
| 149 | ``` |
| 150 | TOTAL extent_scanned=1,466,581,280 EXT_HOLE=0 |
| 151 | pad_scanned = 22,787,296 PAD_HOLE=4,676,128 |
| 152 | fixtures with a nonzero hole in either region: 38 |
| 153 | ``` |
| 154 | |
| 155 | * **Region 2 (true extent): 0 unwritten of 1.47 G scanned.** The withdrawn |
| 156 | defect is gone from the current corpus, and the one fixture that |
| 157 | demonstrated it is refused: |
| 158 | `440_request_is_422` → `REFUSED: unsupported: AV1 tile (a block size 4x8, |
| 159 | 8x16 or 16x4 (or 8x4 at 4:4:0) has no chroma plane block at this frame's |
| 160 | subsampling mode …)` (`decode.rs:21643`). |
| 161 | * **Region 1 (padded tail): 4.68 M unwritten of 22.8 M scanned (20.5 %)** on |
| 162 | 38 fixtures — unwritten *by construction*, since no block lands there. This |
| 163 | is the region whose "nobody reads it" claim had never been measured. |
| 164 | * On the generated 3840x2160 4:2:2 stream the tail is non-zero on the first |
| 165 | two frames and zero after (`pad_unwritten=4096/1024/1024` on frame 0, |
| 166 | `2048/512/512` on frame 1) out of 61 440/15 360/15 360 scanned per frame — |
| 167 | so a 4:2:2 frame does leave real unwritten tail behind at scale. |
| 168 | |
| 169 | ### 2.4 Read census — measurement, and its non-vacuity |
| 170 | |
| 171 | The region census counts **unwritten** samples. It says nothing about reads, |
| 172 | which is the whole question. Two independent read instruments: |
| 173 | |
| 174 | **(a) valgrind memcheck, differential.** Every fixture decoded twice under |
| 175 | memcheck — once on `uninit` (the plane buffer is uninitialised, so any read of |
| 176 | it is a memcheck error) and once on `zeroed`. **128 fixtures × 2 arms = 256 |
| 177 | runs executed, zero uninitialised-value errors, identical error-signature sets |
| 178 | on all 128.** 126 of the fixtures decode; two refuse. The sweep was run in two |
| 179 | pieces — 127 fixtures on the pre-rebase tree, then the fixture that arrived |
| 180 | with `d16af6c3` (`422_header_edge16_walk.obu`, 128 bytes) run separately under |
| 181 | both arms on `f01e9738`: |
| 182 | |
| 183 | ``` |
| 184 | 422_header_edge16_walk.obu uninit 0 zeroed 0 CLEAN (identical) |
| 185 | raw, uninit arm: ERROR SUMMARY: 0 errors from 0 contexts |
| 186 | raw, zeroed arm: ERROR SUMMARY: 0 errors from 0 contexts |
| 187 | ``` |
| 188 | |
| 189 | Those two runs are not vacuous, and that needed checking rather than assuming: |
| 190 | the fixture refuses, so "0 errors" could have meant "the decoder allocated |
| 191 | nothing". It did not. `EC_AV1_SUBSIZE_GUARD_TRACE=1` on it reports six |
| 192 | `note_subsize_guard` sites reached, with the refusal FIRING at |
| 193 | `decode.rs:37522` (`bsize=16x16 part=2 codable=false`) — that site is inside |
| 194 | the tile walk, which is downstream of the three `fresh_plane` calls at |
| 195 | `decode.rs:36007`/`36028`/`36040`. So the plane was allocated, partially |
| 196 | written, and abandoned mid-walk, and memcheck saw an `uninit` buffer with a |
| 197 | real partial write in it and still found nothing. |
| 198 | > |
| 199 | > One consequence for §2.3: this fixture prints **no** `SENTINEL_CENSUS` line, |
| 200 | > because the refusal short-circuits through `?` before the census at the tail |
| 201 | > of `decode_key_frame_tile_with_cdfs`. Its contribution is therefore 0 scanned |
| 202 | > and 0 holes, which is why the §2.3 totals are identical for 127 and for 128 |
| 203 | > files — and also why the census's `scanned` pairing cannot be dropped: a |
| 204 | > fixture that contributes nothing looks exactly like one never looked at. |
| 205 | > |
| 206 | |
| 207 | > **Non-vacuity, by mutation.** A temporary env-gated read of the plane's last |
| 208 | > slot (`v[n-1]`, added to `fresh_plane`, reverted before commit) makes the same |
| 209 | > binary on the same fixture report **12 errors from 4 contexts**: |
| 210 | > `Conditional jump or move depends on uninitialised value(s)` ×3, |
| 211 | > `Use of uninitialised value of size 8`. The instrument sees plane-sourced |
| 212 | > uninitialised reads when they exist. |
| 213 | > |
| 214 | > That run also shows the ambient-content hazard concretely: the luma plane |
| 215 | > (`n=30720`) errored and the two chroma planes (`n=7680`) happened to be handed |
| 216 | > already-zero memory and did not. A same-machine run is not proof; a |
| 217 | > *different* poison is. |
| 218 | |
| 219 | **(b) Differential poisoning.** Decode each fixture under two DIFFERENT |
| 220 | impossible values for the plane buffer and compare the output hash. A read |
| 221 | whose value reaches the picture changes the hash when the poison changes. |
| 222 | |
| 223 | | corpus | arms | result | |
| 224 | |---|---|---| |
| 225 | | 126 committed fixtures | `0xDEAD` / `0xBEEF` / `alloc_zeroed` | **126/126 byte-identical** | |
| 226 | | `440_request_is_422` | — | REFUSED (§2.3) | |
| 227 | | 4K 4:2:0, 4K 4:2:2, 1080p 4:2:0 | `0xDEAD`, `0xBEEF`, `0x0080`, `0x0001`, `0x0FFF`, `0x1000`, `0x2000`, `zeroed` | **8/8 identical per stream** | |
| 228 | |
| 229 | The last row needs a note on method. `plane_poison()` *refuses* a poison at or |
| 230 | below `MAX_LEGAL_SAMPLE` (4095), because a legal poison makes the region census |
| 231 | vacuous. To run the experiment anyway I temporarily removed that guard: the |
| 232 | **legal-range** poisons (`0x0001`, `0x0080`, `0x0FFF`, `0x1000`, `0x2000`) then |
| 233 | produce the same hash as the impossible ones. That matters because an |
| 234 | out-of-range poison can be hidden by a clamp — every legal sample is |
| 235 | `(1 << bit_depth) - 1` at most — while a legal-range poison is not. **No read |
| 236 | survives clamping, masking or branch selection.** The guard is restored. |
| 237 | |
| 238 | ### 2.5 Verdict of the census |
| 239 | |
| 240 | * **Region 1 (padded tail):** exists (4.68 M samples), is never written, and is |
| 241 | **never read** — memcheck over 254 runs and 8 poisons agree. |
| 242 | * **Region 2 (true extent):** **0 holes** across 1.47 G samples on every current |
| 243 | fixture; the historical 224-sample case is behind a refusal. |
| 244 | * **A third category, which neither instrument can see: `pix_write`.** Its |
| 245 | `prev` argument is the destination sample's own value, read at four call |
| 246 | sites on **every** reconstruction store. When a block is the first to write |
| 247 | a sample, that read returns the buffer's initial content. It is still a read |
| 248 | of a `u16` that (on the `uninit` arm) was never written. |
| 249 | * Neither instrument reports it, and that is not a gap in them: `prev` is |
| 250 | only consumed inside `if *PIXPROBE_ON`, so the value never reaches a |
| 251 | branch, an address computation or a syscall — memcheck has nothing to |
| 252 | complain about, and no hash can move. Verified directly: a **debug** build |
| 253 | (no optimisation to dead-code-eliminate the load) under memcheck on the |
| 254 | `uninit` arm still reports `0 errors from 0 contexts`. |
| 255 | * So the honest reading is: the decoder provably does not *depend* on the |
| 256 | buffer's initial content, and `pix_write` is the one place it reads it |
| 257 | anyway. The shipped `Zeroed` closure deletes that read along with the rest, |
| 258 | which is a second, independent reason to take it. |
| 259 | * **A constraint on the census arms that is not obvious from their names.** |
| 260 | `fresh_plane` returns `vec![plane_poison(); n]` BEFORE it matches on |
| 261 | `plane_alloc()`, so `PadZero` and `ExtZero` never run while |
| 262 | `EC_AV1_PLANE_SENTINEL` is set — and that flag is exactly what both census |
| 263 | functions require (each returns early when it is off). Those two arms are |
| 264 | therefore meaningful only under **memcheck with the sentinel OFF**, where |
| 265 | the zeroed/uninitialised split between the regions is what memcheck keys on; |
| 266 | under the sentinel they are inert. The order is deliberate and stays: |
| 267 | moving the sentinel check below the match would let the region census scan a |
| 268 | buffer the sentinel never poisoned, which it cannot recover from. |
| 269 | * **Neither is reachable today.** That is a statement about today's corpus, not |
| 270 | a proof: a hostile file chooses its own subsize values, and the refusal that |
| 271 | closes region 2 lives in the tile walk, not at the allocation. Hence the |
| 272 | decision below rather than "the premise holds". |
| 273 | |
| 274 | --- |
| 275 | |
| 276 | ## 3. The decision, and the evidence behind it |
| 277 | |
| 278 | The charter's rule: *if (b) is within noise of (a) and close to the baseline, |
| 279 | implement (b) and prove determinism; if (b) is expensive and (a) is too, leave |
| 280 | the allocation alone.* |
| 281 | |
| 282 | * (b) **is** within noise of (a) — 0.03 % apart at all three sizes. |
| 283 | * (b) is **not** within noise of the baseline at 4K: +0.84 % with a 6–10 ms |
| 284 | run-to-run spread, i.e. ~6σ. So the charter's first branch is not literally |
| 285 | satisfied. |
| 286 | |
| 287 | I took (b) anyway, and the reason is the shape of the risk, not the size of the |
| 288 | number: |
| 289 | |
| 290 | 1. **The alternative is not "keep the unsafe", it is "keep asserting a premise |
| 291 | that has already been withdrawn once."** That premise is what |
| 292 | `lanes/unwritten-dep.report.md` §12 filed, and it produced a caller-visible |
| 293 | defect. A 0.84 % regression is visible in a benchmark; a withdrawn SAFETY |
| 294 | premise is invisible until it ships. |
| 295 | 2. **The sign of the cost is not stable across resolutions** (§1). A decision to |
| 296 | pay it should be made knowing it is ~0.85 % at 4K and a ~1.6 % *win* at 1080p, |
| 297 | not "always 0.8 %". |
| 298 | 3. **The decision is reversible in one line.** `EC_AV1_PLANE_ALLOC=uninit` |
| 299 | restores the status quo exactly, which is only true because the closure is an |
| 300 | env arm and not a build flag. |
| 301 | |
| 302 | **Determinism proof** — new gate |
| 303 | `stream::tests::the_frame_does_not_depend_on_the_plane_buffers_initial_content` |
| 304 | (`stream.rs:48496`), which is exactly the charter's test: |
| 305 | |
| 306 | * four child processes, same ten fixtures each: `EC_AV1_PLANE_SENTINEL=0xDEAD`, |
| 307 | `EC_AV1_PLANE_SENTINEL=0xBEEF`, sentinel-off + `EC_AV1_PLANE_ALLOC=uninit`, |
| 308 | sentinel-off + `EC_AV1_PLANE_ALLOC=zeroed`; |
| 309 | * one FNV-1a hash per fixture over every shown frame's Y/U/V samples; all four |
| 310 | arms must agree, per fixture; |
| 311 | * **non-vacuity first, synthetic**: two pictures differing in ONE sample must |
| 312 | hash differently, or every equality below would be vacuous; |
| 313 | * every arm must report `frames > 0`, so a child that decoded nothing cannot |
| 314 | agree with another child that decoded nothing. |
| 315 | |
| 316 | Fixture list deliberately small: a first revision used the 1920x792 film |
| 317 | fixtures and took **252 s** in a debug build, which is not a gate anyone keeps. |
| 318 | The committed ten (4:2:2 12-bit key / inter / sb128 intrabc / 17-frame odd |
| 319 | size, 4:4:4 lossless-sb64 / intrabc-rect4 / 128-root-mu, a padded odd size, an |
| 320 | off-tile chroma walk, superres+CDEF+LR) run the gate in **4.6 s**. |
| 321 | |
| 322 | --- |
| 323 | |
| 324 | ## 4. What changed |
| 325 | |
| 326 | * `decode.rs` — `PlaneAlloc` (five arms), `plane_alloc()`, `zero_pad()`, |
| 327 | `zero_extent()`, `plane_poison()` (a settable poison so two-value |
| 328 | differential poisoning is possible; a poison ≤ 4095 is still refused), |
| 329 | `MAX_LEGAL_SAMPLE`, the pad-tail census (`PAD_UNWRITTEN_SAMPLES`, |
| 330 | `PAD_CENSUS_SCANNED` + accessors), `census_unwritten` extended to scan both |
| 331 | regions, `census_unwritten_final` switched to `plane_poison()`, |
| 332 | `fresh_plane` taking the plane geometry, and **`PlaneAlloc::Zeroed` as the |
| 333 | default**, which puts the `unsafe` behind an env arm. |
| 334 | * `stream.rs` — the determinism gate, its child, and the synthetic control. |
| 335 | * `examples/alloc_timing.rs` — the decode-wall-time / page-fault harness. |
| 336 | * Hunks are confined to the allocation path: `decode.rs` `fresh_plane` and the |
| 337 | six `PlaneBuf { … }` construction sites (3 planes × the key and inter frame |
| 338 | functions), plus the census block next to them. The peer lane |
| 339 | `lane/av1subsizesweep` touches `decode.rs` at ~37063 and ~57061 (a |
| 340 | superblock arm and its tests); there is no overlap. |
| 341 | |
| 342 | ### SAFETY comment |
| 343 | |
| 344 | Rewritten to state **what can be read before it is written** — the three named |
| 345 | regions with their measured counts, the memcheck result, the refusal that |
| 346 | covers region 2, and the fact that the shipped arm never reaches the `unsafe` |
| 347 | at all. The withdrawn premise ("written sample-for-sample before anything reads |
| 348 | it") is gone; nothing in the comment asserts a premise a reviewer cannot |
| 349 | re-run. |
| 350 | |
| 351 | --- |
| 352 | |
| 353 | ## 5. Gates |
| 354 | |
| 355 | ``` |
| 356 | cargo check -p ec-av1 --tests ok |
| 357 | cargo test -p ec-av1 --lib -- 422 14 passed, 0 failed |
| 358 | cargo test -p ec-av1 --lib -- 444 50 passed, 0 failed |
| 359 | cargo test -p ec-av1 --lib -- sub8 13 passed, 0 failed |
| 360 | cargo test -p ec-av1 --lib -- lossless 34 passed, 0 failed |
| 361 | ``` |
| 362 | Re-run on the rebased tree (`f01e9738`), where main's own `1f4fcc84` guard for |
| 363 | the census child test is present: |
| 364 | ``` |
| 365 | cargo test -p ec-av1 --lib -- the_frame 13 passed, 0 failed |
| 366 | (includes the_frame_does_not_depend_on_the_plane_buffers_initial_content) |
| 367 | cargo test -p ec-av1 --lib -- unwritten 2 passed, 0 failed |
| 368 | ``` |
| 369 | |
| 370 | **One gate was red on the lane's original base and is not this lane's.** On |
| 371 | `2d8fa8a4`, `cargo test -p ec-av1 --lib -- unwritten` reported |
| 372 | `1 passed, 1 FAILED`: `stream::tests::uwdep_child_unwritten_census` opens with |
| 373 | an unconditional `assert!(EC_AV1_PLANE_SENTINEL is set)` while sitting in the |
| 374 | crate's default test list, so any standalone run of that filter fails. Main |
| 375 | commit `1f4fcc84` ("the census child test skips in a normal suite run instead |
| 376 | of reddening it") adds the entry guard and it is **not** an ancestor of this |
| 377 | lane's original base. Nothing in this lane touches that test. |
| 378 | |
| 379 | --- |
| 380 | |
| 381 | ## 7. Rebase onto `f01e9738` |
| 382 | |
| 383 | Main moved while this lane was measuring. The branch is rebased onto `f01e9738` |
| 384 | and every headline number was re-taken there; the only conflict was in the |
| 385 | `census_unwritten` doc comment, resolved by keeping main's coverage paragraph |
| 386 | ("this census runs at TWO of the four places `apply_deblock` is entered from") |
| 387 | *and* the two-region text, since both intents hold. Main's delta also adds |
| 388 | `chroma_plane_block_codable` to the 16-level edge arm — the guard that refuses |
| 389 | the 4:2:2 subsize by name. |
| 390 | |
| 391 | What changed on the rebased tree, re-measured: |
| 392 | * the 3840x2160 4:2:0 row (§1) — `zeroed` +0.84 %, `fill` +0.92 %; same hashes, |
| 393 | same `minflt`, same conclusion; |
| 394 | * the poison sweep — 126 identical, **2** refused: `440_request_is_422` and, |
| 395 | newly, `422_header_edge16_walk`, which main's new guard refuses; |
| 396 | * the region census — **byte-identical totals**: 1,466,581,280 extent samples, |
| 397 | 0 holes; 22,787,296 pad samples, 4,676,128 holes; 38 fixtures. |
| 398 | |
| 399 | --- |
| 400 | |
| 401 | ## 8. Left undone, deliberately |
| 402 | |
| 403 | * **A pooled plane buffer** would make the closure ~free: take the three plane |
| 404 | buffers from a thread-local pool, zero each ONCE at creation, return them on |
| 405 | drop. Every sample is then initialised by construction and the per-frame |
| 406 | memset disappears. It is not done here because it changes ownership |
| 407 | (`PlaneBuf` holds `Cow<'a, [u16]>` and is handed to the wavefront workers), |
| 408 | which is a different lane's worth of risk than this charter took on. |
| 409 | * **The 1080p sign flip is unexplained.** §1. |
| 410 | * **Reader attribution for a region-2 read** is only as deep as "a reader that |
| 411 | does not clamp". With no current fixture reaching region 2 there is nothing to |
| 412 | attribute; `EC_AV1_PLANE_ALLOC=padzero` / `extzero` are in the tree for |
| 413 | whoever gets one — under memcheck with the sentinel OFF, per the ordering |
| 414 | constraint in §2.5. |