Repository navigation
fix(preview): avoid redundant AVIF and HEIF decodes - #1971
Conversation
Read bounded primary-item spatial extents and rotation from ISO BMFF headers, then reuse probed dimensions in the existing pixbuf renderers. Keep decoder fallbacks and frame budgets intact, and extend the camera-format QA owner without duplicating fixture setup. Refs #1968
Validation and benchmark reproductionScope: bounded image decoding/metadata change, not a worker-pool, dependency, preference, or input-routing change. Coverage includes the shared image/RAW renderers and their fallbacks/budgets, sandbox transport/lifecycle, remote preview staging/cancellation, and the real camera-format thumbnail/preview paths. No repository-rule overrides were used. Completed checks
The new AVIF cost hint (0.4) is calibrated against the existing HEIC 0.4 weight: three scoped-run medians were 1.971 s for AVIF and 1.895 s for HEIC. Other historical weights are retained. A full global cost refresh was not run. Intentional omissions: full local Rust and QA suites were not run for this bounded change; required CI remains the full gate before merge. The local QA quality rating remains I/C/K/D 3/3/4/4, score 33. Independent Haiku grading was attempted but unavailable because the configured model gateway rejected the model; it is not reported as passed. One initial cold native build was interrupted for memory pressure and repeated with debug information disabled/two jobs. An initial empty-fixture drive without a private session bus did not reach readiness; it was stopped and replaced with the seeded/private-bus session above, never a desktop fallback. Reproduce the benchmarkThe PR description contains the before/after measurements. The harness uses the same fixture and six calls per operation (one warm-up, then the median of five samples). CPU totals are shell Generate the fixture: mkdir -p target/issue-1968
magick -limit thread 4 -seed 1968 -size 4000x3000 plasma:fractal target/issue-1968/source.png
avifenc --jobs 4 --speed 9 -q 30 target/issue-1968/source.png target/issue-1968/photo.avifFor each revision, temporarily save the following as #[path = "../../target/issue-1968/benchmark.rs"]
mod issue_1968_benchmark;Temporary benchmark sourceuse std::{path::Path, time::{Duration, Instant}};
fn median(mut run: impl FnMut()) -> Duration {
run();
let mut samples = Vec::new();
for _ in 0..5 {
let start = Instant::now();
run();
samples.push(start.elapsed());
}
samples.sort();
samples[2]
}
#[test]
#[ignore = "temporary issue 1968 performance reproduction"]
fn avif_decode_work_is_not_repeated() {
use crate::sandbox::browser::wire::Operation;
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("target/issue-1968/photo.avif");
let single = median(|| {
let pixbuf = gdk_pixbuf::Pixbuf::from_file_at_scale(&path, 800, 800, true)
.expect("decode AVIF");
std::hint::black_box(
pixbuf.save_to_bufferv("png", &[("compression", "1")])
.expect("encode PNG")
);
});
let preview = median(|| {
assert!(!super::super::browser_render(&path, Operation::PreviewImage)
.png.is_empty());
});
let thumbnail = median(|| {
assert!(!super::super::browser_render(&path, Operation::Image)
.png.is_empty());
});
let metadata = median(|| {
assert!(!super::super::browser_render(&path, Operation::ImageMetadata)
.metadata.is_empty());
});
eprintln!("single={single:?} preview={preview:?} thumbnail={thumbnail:?} metadata={metadata:?}");
assert!(preview.as_secs_f64() / single.as_secs_f64() < 2.0);
assert!(thumbnail.as_secs_f64() / single.as_secs_f64() < 2.0);
assert!(metadata.as_secs_f64() / single.as_secs_f64() < 0.1);
}Prebuild/run once without timing, then run the same command on the baseline and PR revision: TIMEFORMAT='wall=%R user=%U system=%S'
time ./scripts/test-headless.py --config profile.dev.debug=0 --config profile.test.debug=0 -j 2 avif_decode_work_is_not_repeated -- --ignored --nocaptureRemove the temporary module declaration afterward. No benchmark source, generated image, log, screenshot, or report is committed. |
|
Follow-up profiling for the request to go faster (no production-code changes): on the same 12 MP fixture, fresh CLI medians were 1,227 ms for the current preview helper, 2,001 ms for the existing ImageMagick renderer, and 655 ms for an exploratory FFmpeg RGBA8 path with one decoder/filter thread. This CLI comparison includes process startup and is separate from the in-process benchmark in the description. The FFmpeg prototype is not a safe drop-in: a transparent AVIF rendered by Strata retained alpha range 0–1, while the prototype became fully opaque (1–1). A 90-degree rotation fixture produced the correct 40×80 dimensions in both paths, but ICC/HDR behavior is not yet validated. Bare There is potential headroom, but a faster path needs complete image semantics rather than a quality-breaking decoder swap. The current branch remains unchanged and all required CI checks now pass. No additional production speedup or CPU reduction is being claimed from these exploratory measurements. |
ReviewMerged What was checked
Local verification (worktree, native)
CI on |
Description
Reuse callers' dimension results instead of probing again in the pixbuf renderer. Read AVIF/HEIF primary-item dimensions and rotation from bounded ISO BMFF metadata, keeping the existing renderers, decode budgets, and compatibility fallbacks. Extend the existing camera-format scenario with AVIF and share its fixture setup.
Benchmark
Same synthetic 4000×3000, 12-bit AVIF (123 KB), one warm-up and five measured runs per operation; table values are medians. These call the real helper functions in-process, outside the decoder sandbox, under private Xvfb/D-Bus. Preview/reference use an 800 px edge; thumbnails use 256 px.
54% less measured CPU time. Preview cost falls from 2.82× to 1.05× the single-decode reference; thumbnails from 2.28× to 1.27×. The reference timings show normal machine-load variation, not an improvement to the codec itself. CPU totals include warm-ups and reference decodes, not just preview work. The temporary reproduction harness is recorded in the validation comment, not added as a flaky timing test.
Visual evidence
N/A — decoder performance change; the interface is unchanged.
How to test
Expected result: Correct thumbnails, previews, and oriented dimensions. Supported AVIF/HEIF headers provide dimensions without decoding pixels; each normal image render needs one full decode rather than three. Unsupported or cropped metadata retains the existing decoder fallback.
Related issue
Closes #1968