Make WordPress Core

#61758 closed defect (bug) (fixed)

Improve speed of AVIF image generation

Reported by: adamsilverstein's profile adamsilverstein Owned by: adamsilverstein's profile adamsilverstein
Milestone: 6.7 Priority: normal
Severity: normal Version: 6.5
Component: Media Keywords: has-patch
Focuses: performance, sustainability Cc:

Description

As raised on the Performance Lab plugin (Issue), compressing AVIF images can be much slower that compressing that came image into WebP or JPEG formats. For normal image uploads this isn't an issue because the total time to compress a single image to all sizes in AVIF on a reasonably powered WordPress server is still less than a second (see issue for discussion). When recompressing a large number of images, however, this could be a real problem.

The AVIF encoder does work harder to achieve much better compression, however we can improve the performance of this operation by raising the `heic:speed` Imagick AVIF option to 7 (the default is 5). This will result in a bit faster processing with no loss of quality - the default value is essentially too low.

Change History (12)

@adamsilverstein commented on PR #7068:


20 months ago
#2

Tests repeated 50 times using my image test plugin.

A JPEG test image is converted into four sizes and three mime formats using WordPress's media functions.

These results are times in seconds from running on my local install using Imagick and PHP 7.4:

Total times with AVIF's heic:speed at 5 (default)

(

[image/jpeg] => Array

(

[total] => 1.362594127655

)

[image/webp] => Array

(

[total] => 2.3467826843262

)

[image/avif] => Array

(

[total] => 4.1179628372192

)

)

AVIF is 3x slower than JPEG


Total times with AVIF's heic:speed at 7 (applied at top of function)
(

[image/jpeg] => Array

(

[total] => 1.3803205490112

)

[image/webp] => Array

(

[total] => 2.3556952476501

)

[image/avif] => Array

(

[total] => 3.1982583999634

)

)
AVIF is now 2.3X slower

#3 @adamsilverstein
20 months ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


20 months ago

#5 @adamsilverstein
19 months ago

  • Milestone changed from Awaiting Review to 6.7

#6 @adamsilverstein
19 months ago

  • Focuses sustainability added

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


19 months ago

@mukesh27 commented on PR #7068:


19 months ago
#8

@adamsilverstein I used your mini plugin to test processing time by mime type using WordPress - https://gist.github.com/adamsilverstein/b4e91c9ab1e6f546ec98e3dcc53afb7d and record the total time.

### Total times in Current core:

[total_time] => Array
        (
            [image/jpeg] => Array
                (
                    [start] => 1724909008.4779
                    [end] => 1724909008.503
                    [total] => 0.025084018707275
                )

            [image/webp] => Array
                (
                    [start] => 1724909008.519
                    [end] => 1724909008.5804
                    [total] => 0.061421871185303
                )

            [image/avif] => Array
                (
                    [start] => 1724909008.5964
                    [end] => 1724909010.0521
                    [total] => 1.4556329250336
                )

        )

### Total times with AVIF's heic:speed at 5

[total_time] => Array
        (
            [image/jpeg] => Array
                (
                    [start] => 1724909068.6723
                    [end] => 1724909068.6965
                    [total] => 0.0241539478302
                )

            [image/webp] => Array
                (
                    [start] => 1724909068.7124
                    [end] => 1724909068.7733
                    [total] => 0.060920000076294
                )

            [image/avif] => Array
                (
                    [start] => 1724909068.7891
                    [end] => 1724909070.223
                    [total] => 1.4339118003845
                )

        )

### Total times with AVIF's heic:speed at 7

[total_time] => Array
        (
            [image/jpeg] => Array
                (
                    [start] => 1724909110.122
                    [end] => 1724909110.1462
                    [total] => 0.024223804473877
                )

            [image/webp] => Array
                (
                    [start] => 1724909110.162
                    [end] => 1724909110.2212
                    [total] => 0.059128046035767
                )

            [image/avif] => Array
                (
                    [start] => 1724909110.2368
                    [end] => 1724909111.6732
                    [total] => 1.4363379478455
                )

        )

AVIF generation has improved from taking 1.4556 seconds to taking 1.4363 seconds (a 1.33% reduction)

<details>

<summary>Site Health: PHP Version 8.2.19</summary>

### wp-core ###

version: 6.7-alpha-58576-src
site_language: en_US
user_language: en_US
timezone: +00:00
permalink: /%year%/%monthnum%/%day%/%postname%/
https_status: false
multisite: false
user_registration: 0
blog_public: 1
default_comment_status: open
environment_type: local
user_count: 1
dotorg_communication: true

### wp-paths-sizes ###

wordpress_path: /var/www/src
wordpress_size: 95.81 MB (100463863 bytes)
uploads_path: /var/www/src/wp-content/uploads
uploads_size: 88.59 MB (92889409 bytes)
themes_path: /var/www/src/wp-content/themes
themes_size: 36.84 MB (38632957 bytes)
plugins_path: /var/www/src/wp-content/plugins
plugins_size: 363.34 KB (372057 bytes)
fonts_path: /var/www/src/wp-content/uploads/fonts
fonts_size: 0.00 B (0 bytes)
database_size: 1.73 MB (1818624 bytes)
total_size: 223.33 MB (234176910 bytes)

### wp-active-theme ###

name: Twenty Twenty-Four (twentytwentyfour)
version: 1.2
author: the WordPress team
author_website: https://wordpress.org
parent_theme: none
theme_features: core-block-patterns, post-thumbnails, responsive-embeds, editor-styles, html5, automatic-feed-links, widgets-block-editor, block-templates
theme_path: /var/www/src/wp-content/themes/twentytwentyfour
auto_update: Disabled

### wp-themes-inactive (13) ###

Twenty Eleven: version: 4.7, author: the WordPress team, Auto-updates disabled
Twenty Fifteen: version: 3.8, author: the WordPress team, Auto-updates disabled
Twenty Fourteen: version: 4.0, author: the WordPress team, Auto-updates disabled
Twenty Nineteen: version: 2.9, author: the WordPress team, Auto-updates disabled
Twenty Seventeen: version: 3.7, author: the WordPress team, Auto-updates disabled
Twenty Sixteen: version: 3.3, author: the WordPress team, Auto-updates disabled
Twenty Ten: version: 4.2, author: the WordPress team, Auto-updates disabled
Twenty Thirteen: version: 4.2, author: the WordPress team, Auto-updates disabled
Twenty Twelve: version: 4.3, author: the WordPress team, Auto-updates disabled
Twenty Twenty: version: 2.7, author: the WordPress team, Auto-updates disabled
Twenty Twenty-One: version: 2.3, author: the WordPress team, Auto-updates disabled
Twenty Twenty-Three: version: 1.5, author: the WordPress team, Auto-updates disabled
Twenty Twenty-Two: version: 1.8, author: the WordPress team, Auto-updates disabled

### wp-plugins-active (1) ###

Profile image processing: version: 1.0.0, author: Adam Silverstein, Google, Auto-updates disabled

### wp-media ###

image_editor: WP_Image_Editor_Imagick
imagick_module_version: 1691
imagemagick_version: ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org
imagick_version: 3.7.0
file_uploads: 1
post_max_size: 1G
upload_max_filesize: 1G
max_effective_size: 1 GB
max_file_uploads: 20
imagick_limits:

imagick::RESOURCETYPE_AREA: 122 MB
imagick::RESOURCETYPE_DISK: 1073741824
imagick::RESOURCETYPE_FILE: 786432
imagick::RESOURCETYPE_MAP: 512 MB
imagick::RESOURCETYPE_MEMORY: 256 MB
imagick::RESOURCETYPE_THREAD: 1
imagick::RESOURCETYPE_TIME: 9.2233720368548E+18

imagemagick_file_formats: 3FR, 3G2, 3GP, AAI, AI, APNG, ART, ARW, AVI, AVIF, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FILE, FITS, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, H, HALD, HDR, HEIC, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIDEO, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV
gd_version: bundled (2.1.0 compatible)
gd_formats: GIF, JPEG, PNG, WebP, BMP
ghostscript_version: 9.53.3

### wp-server ###

server_architecture: Linux 6.5.11-linuxkit x86_64
httpd_software: nginx/1.27.0
php_version: 8.2.19 64bit
php_sapi: fpm-fcgi
max_input_variables: 1000
time_limit: 30
memory_limit: 128M
admin_memory_limit: 256M
max_input_time: -1
upload_max_filesize: 1G
php_post_max_size: 1G
curl_version: 7.74.0 OpenSSL/1.1.1w
suhosin: false
imagick_availability: true
pretty_permalinks: true
current: 2024-08-29T05:32:35+00:00
utc-time: Thursday, 29-Aug-24 05:32:35 UTC
server-time: 2024-08-29T05:32:32+00:00

### wp-database ###

extension: mysqli
server_version: 8.0.37
client_version: mysqlnd 8.2.19
max_allowed_packet: 67108864
max_connections: 151

### wp-constants ###

WP_HOME: undefined
WP_SITEURL: undefined
WP_CONTENT_DIR: /var/www/src/wp-content
WP_PLUGIN_DIR: /var/www/src/wp-content/plugins
WP_MEMORY_LIMIT: 40M
WP_MAX_MEMORY_LIMIT: 256M
WP_DEBUG: true
WP_DEBUG_DISPLAY: true
WP_DEBUG_LOG: true
SCRIPT_DEBUG: true
WP_CACHE: false
CONCATENATE_SCRIPTS: undefined
COMPRESS_SCRIPTS: undefined
COMPRESS_CSS: undefined
WP_ENVIRONMENT_TYPE: local
WP_DEVELOPMENT_MODE: core
DB_CHARSET: utf8
DB_COLLATE: undefined

### wp-filesystem ###

wordpress: writable
wp-content: writable
uploads: writable
plugins: writable
themes: writable
fonts: writable
</details>

This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.


18 months ago

#12 @adamsilverstein
18 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 59042:

Media: improve speed of AVIF image generation.

Set the AVIF encoder to work faster by raising heic:speed to 7 from the default of 5. AVIF generation time is reduced by up to 20% with minimal impact on image size.

Props: adamsilverstein, erikyo, mukesh27, yguyon, felixarntz, jzern.
Fixes #61758.

Note: See TracTickets for help on using tickets.