How Lighthouse Calculates AVIF Byte Savings
Google Lighthouse evaluates page performance by identifying opportunities to reduce payload sizes, including migrating legacy image formats to next-generation formats like AVIF. Instead of performing intensive, real-time image re-encoding during an audit, Lighthouse relies on empirical heuristic models to estimate the compressed size of images converted to AVIF. By subtracting this estimated file size from the original transfer size and filtering the results against specific minimum thresholds, Lighthouse calculates the total potential byte savings reported in its audits.
1. Identifying Eligible Images
Before any calculations occur, Lighthouse analyzes the page’s network activity to identify candidate images during the "Modern Image Formats" audit. The tool inspects network requests and filters for raster formats that benefit from modern compression, primarily JPEG, PNG, and older WebP files. Vector graphics (SVG), icons, and images that are already served as AVIF are excluded from the calculation.
2. Heuristic Size Estimation
Encoding full-resolution images into AVIF during a client-side audit would require excessive CPU resources and significantly slow down the auditing process. To avoid this overhead, Lighthouse uses an empirical estimation algorithm based on image dimensions and visual density rather than performing actual compression:
- Pixel Area Calculation: Lighthouse determines the display and intrinsic dimensions of the image to compute total pixel count.
- Target Bytes-per-Pixel Heuristic: Based on extensive benchmarking of AVIF compression efficiency at standard web quality settings (typically around quality 50–60, where AVIF retains strong fidelity), Lighthouse applies a baseline bytes-per-pixel or target compression ratio.
- Format-Specific Comparison: For typical JPEG or PNG images, AVIF generally offers 20% to 50% better compression than WebP and substantially higher savings over standard JPEG/PNG. Lighthouse uses these benchmarked ratios to model the expected file size of the converted asset.
3. Calculating Potential Byte Savings
Once the estimated AVIF size is calculated, Lighthouse determines the savings for each image:
\[\text{Byte Savings} = \text{Original Transfer Size} - \text{Estimated AVIF Size}\]
If the original image is already compressed heavily enough that an AVIF version would yield negligible or negative savings, the calculation returns zero savings for that file.
4. Applying Minimum Thresholds
To keep audit reports actionable and prevent flagging minor optimizations that have virtually no impact on page load times, Lighthouse applies thresholds:
- Per-Image Minimum: Individual images must provide a minimum byte reduction (typically at least 2 KiB to 4 KiB) to appear in the audit recommendations.
- Audit Failure Threshold: The overall audit only flags the recommendation if total potential savings across all candidate images exceed a meaningful performance threshold (commonly 8 KiB or more).
5. Final Aggregation and Scoring
Lighthouse aggregates all individual byte savings that exceed the threshold to display the total potential data reduction in KiB or MiB. It also estimates the potential load time improvement (in milliseconds) based on the simulated network conditions of the run, giving developers a clear metric of how adopting AVIF will improve page delivery.