Make WordPress Core

Opened 6 weeks ago

Last modified 3 hours ago

#61532 assigned defect (bug)

Improve the performance of `WP_Image_Editor_Imagick::supports_mime_type()`

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

Description

WP_Image_Editor_Imagick::supports_mime_type() is called whenever WordPress is choosing which image editor library to use via wp_image_editor_supports() > _wp_image_editor_choose().

To see if the current server's version of ImageMagick supports a specific mime type, that method calls Imagick::queryFormats(), which can take a long time to run.

In the editor, wp_plupload_default_settings() makes triggers this code path to see if modern formats like WebP and AVIF are supported, which leads to a slower editor load time.

Since these supports values rarely change except for when changing hosting environments, we can cache these supports values for faster lookups.

Change History (5)

This ticket was mentioned in PR #6936 on WordPress/wordpress-develop by @joemcgill.


6 weeks ago
#1

  • Keywords has-patch added

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


6 hours ago

@adamsilverstein commented on PR #6936:


6 hours ago
#3

Great idea, love it! Curious how you came to the realization that the mime type check call was slow/expensive? Did you see it in a trace somewhere?

@adamsilverstein commented on PR #6936:


5 hours ago
#4

I think a more comprehensive solution would be to cache part of what _wp_image_editor_choose() does, for example:

Interesting idea to add caching up at this level, although this PR's changes could still be useful for supports_mime_type since that could be called from elsewhere including plugins.

My one concern would be ensuring the cache has some expiration so we can catch new capabilities when users upgrade their systems. This brings me back to wondering how significant this improvement is - does profiling indicate this function is problematic?

@flixos90 commented on PR #6936:


3 hours ago
#5

My one concern would be ensuring the cache has some expiration so we can catch new capabilities when users upgrade their systems. This brings me back to wondering how significant this improvement is - does profiling indicate this function is problematic?

This is a good point, would be good to clarify _how_ bad the performance of the uncached function makes it. And related to expiration, I wonder: @joemcgill Are you thinking this should be persistently cached, or would it already benefit to be cached non-persistently (e.g. because the function is called many times during a single page load)?

Note: See TracTickets for help on using tickets.