Repository navigation
Description
Context
Batch J (architecture audit M1) added resize_only_bench_baseline_vs_reused_proves_amortization in crates/media/src/thumbnail.rs to verify the per-worker fast_image_resize::Resizer amortization landed in #111. The test compares per-call Resizer::new() vs a single shared Resizer across N=20 iterations of a 1920×1080 RGB resize.
Problem
The intended ≥5% speedup assertion was empirically too noisy to enforce. A 15-run release reproduction on the maintainer's VM showed:
- 11 PASS, 4 FAIL (27% flake rate against ≥1.05 threshold)
- Per-run speedup ratio swings 0.890x — 1.049x — i.e. some runs measured the reused Resizer as slower than per-call allocation
- Mean ~1.02x, well below the audit's 10% target and the conservative 5% lower bound
The signal is dominated by per-iter DynamicImage::clone() (~6 MB memcpy per 1920×1080 RGB image) plus the WebP encode round-trip in the existing resize_image() path. The Resizer-internal scratch-buffer + CPU-extension dispatch cache savings are a tiny fraction of that wall-clock.
Mitigations to investigate
- Bypass
DynamicImage::clone()— pre-allocate one sourceImage<&[u8]>and callresizer.resize(&src, &mut dst, None)directly, without going throughresize_image()'s coercion + WebP encode path. - Subtract a pure-clone-baseline pass from total wall-clock to expose the Resizer-only delta.
- Use
fast_image_resize's upstream benchmark methodology —Image::from_vec_u8source + same destination buffer reused across iters. - Adopt
criterionworkspace dep for statistical rigor (warmup + outlier rejection). Currently rejected as out-of-charter (Batch J spec §4.2 / §14) — revisit when a 2nd benchmark surfaces.
Current state
The test is committed as print-only (no assertion) per spec §7 option B + §8 risk #4. The eprintln line still surfaces baseline + reused durations + ratio so a human reading CI logs can spot a regression by eye, but the bare assertion would create false-positive CI failures at the observed flake rate.
Acceptance
A restructured test that:
- Runs in
cargo nextest run -p perima-mediadebug + release without#[ignore] - Asserts a stable threshold (≥5% if achievable; lower if the signal floor genuinely isn't there with
image::DynamicImage-shaped inputs) - Documents the methodology in a WHY-block referencing this issue + spec §8 risk rustfmt nightly-only options produce warnings on stable #4
If a 5% assertion remains unstable after restructuring, document why and either lower the threshold (per spec §7 option A) or keep it print-only with a closing comment explaining the limitation.
References
- Batch J spec §7 noise-floor calibration + §8 risk rustfmt nightly-only options produce warnings on stable #4
crates/media/src/thumbnail.rs::resize_only_bench_baseline_vs_reused_proves_amortizationfast_image_resizeREADME benchmarks for comparison data points
Activity
test(media): convert resize_only_bench to print-only; track follow-up #…
arch-audit v0.6.x — checkpoint: Batches F→J landed (#136)