perf(media): track the web cache budget incrementally
Every new web media entry recomputed the eviction budget with two full cache scans. Maintain reclaimable bytes and entry count alongside mutations, so the below-limit budget check is constant time. Eviction order, delivery claims, account namespaces, staged-upload exclusion and the oversized-arrival exception stay intact. Production changes are confined to crates/daemon/src/media/web.rs; no new production dependencies or manifest changes.
Eleven alternating paired release samples per scenario, same runner, synthetic 1 KiB entries. Medians below are milliseconds per fill/clear cycle, including allocation, mutation and eviction. Native and ordinary wasm use rustc 1.99.1; shared wasm uses CI's pinned nightly, rebuilt std and the repository's production wasm flags. The shared probe asserts the actual SharedArrayBuffer memory type.
| Entries | Host probe base → head | Browser wasm base → head | Shared browser wasm base → head |
|---|---|---|---|
| 256 | 0.871 → 0.072 | 1.160 → 0.049 | 1.177 → 0.067 |
| 1024 | 13.916 → 0.288 | 18.276 → 0.218 | 18.515 → 0.301 |
| 4096 | 240.012 → 1.343 | 310.396 → 1.197 | 310.536 → 1.534 |
| 4200 | 292.106 → 44.487 | 393.849 → 52.044 | 377.113 → 51.603 |
These isolate the actual cache algorithm using extracted pure dependency shims. They do not measure the whole page, decode/network performance or browser CPU/heap. No memory-reduction claim. Over-limit sorting remains O(n log n). A separate native removal-only probe found a cost of about 7 µs per 1024 takes, a median paired increase of 9.5%; batch wipe timings were similar.
Validation: formatting and diff checks passed. Real browser suite passed 16 daemon + 32 session tests. The actual cache tests also passed with production shared-memory flags, 5 passed, 0 failed. Four new regressions cover duplicate writes, take, eviction, oversized media, staged payloads, account clear/removal and stale-write errors. A 50,000-operation differential trace matched base/head. Codex completed review of final head 39e67c0 without findings. CI, browser tests, all four platform builds and downloaded release archive verification passed.
Full method, reproduction commands, raw sample scope and limitations. Reproducible native/browser harnesses are in crates/daemon/tests/media_cache*_bench.py; browser mode accepts --shared.