Skip to content

Imagick::queryFormats is slow, loaded on most admin pages #884

@joehoyle

Description

@joehoyle

wp_plupload_default_settings() calls:

	// Check if WebP images can be edited.
	if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
		$defaults['webp_upload_error'] = true;
	}

	// Check if AVIF images can be edited.
	if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
		$defaults['avif_upload_error'] = true;
	}

This in-turn does a Imagick::queryFormats per support, which is quite slow. E.g.

www-data@efddc66a02b9:/usr/src/app$ php -r '$start = microtime(true); var_dump( Imagick::queryFormats( "webp" ) ); var_dump( microtime( true ) - $start );'
array(0) {
}
float(0.0890190601348877)

This is pretty consistent. Given these is constant, I'm wondering if we could cache / hardcode this.

There doesn't appear to be any great hooks to be able to do that but might need more investigation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions