Performance Field Guide for WordPress 6.1
WordPress 6.1 introduces a number of important performance improvements which will have impact in all aspects. The most significant improvements are done in caching
WP_Query as well as REST API.
Improvements to WP_Query
Database queries in WP_Query being cached is a long wanted feature for many developers and finally a dream come true in WordPress 6.1. A couple of new functions will ensure that users cache and linked objects for menu items are now primed while
get_page_by_title function will from now on use
WP_Query and take the full advantage of all these improvements.
Trac tickets holding these changes: #22176, #55716, #55620, #36905.
Improvements to REST API
Priming caches in a single query will significantly improve Posts controller with several new helper functions but that’s not all. User and comments controller will benefit in a similar way while taxonomy and post type controllers are now going to
prepare_links only when needed. This control over
prepare_links method will be available for custom controllers as well.
Trac tickets holding these changes: #52992, #56019, #56020, #55592, #55593, #55620, #55674, #56272.
Site Health improvements
WordPress 6.1 will have two new Site Health checks – Persistent Object Cache and Page Cache, along with a number of new filters. Find out more in dedicated Dev note.
Trac tickets holding these changes: #56040, #56041.
Improvements to multisite
In WordPress 6.1 the network options functions have been updated to be consistent with other metadata types, support for
register_meta is added, prime caching network options in a single query, string main site ID in network options and more.
Trac tickets holding these changes: #37181, #55802.
The order of action hooks is slightly changed in order to gain more control over caching behavior, preloading assets and conditionally executing redirects.
Trac ticket holding these changes: #56068.
Improvements to Cache API
Cache API improvements bring validating cache keys in
WP_Object_Cache methods, deleting cache by group and making a number of private cache priming functions public, and thus, available for usage in plugins and themes.
A valid cache key must be either an integer number or a non-empty string. This will prevent silent failing in
wp_cache_*() functions, done by a quick type check and adding a
_doing_it_wrong() message if the string is empty,
null. Also, a check in
clean_user_cache() will make sure that the email is not empty before being cached or removed from cache. Read more in #56198.
Several private cache priming functions for various object types are now public and plugin and theme authors are encouraged to use these functions to improve the performance of their code by reducing the number of database queries. These functions are:
Read more in #56386.
If you wanted to delete cached item with
wp_cache_delete you had to specify the item’s ID, or you had to flush the entire cache with
wp_cache_flush. WordPress 6.1 introduces a new plugable function called
wp_cache_flush_group which removes all cache items in a group, if the object cache implementation supports it.
Developers can now detect if their current implementation of an object cache supports flushing by group, by calling
wp_cache_supports( $feature ) which returns true if the feature is supported. Third-party object cache plugins can declare a
wp_cache_supports() function and correctly list their supported features:
wp_cache_supports() function replaces and supersedes the
wp_cache_supports_group_flush() function added in #4476.
Read more in #56605.
WordPress 6.1 will add
decoding="async" to image attributes, along with new
wp_img_tag_add_decoding_attr() function and
wp_img_tag_add_decoding_attr filter. Read more in #53232.
Query-attachments AJAX endpoint now caches the parent post objects. Read more in #56037.
WP_Media_List_Table class will call
update_post_parent_caches function in order to prime parent caches in a single database request. Read more in #56036.
Added caching to
wp_count_attachments() for better consistency with
wp_count_posts(). Read more in #55227.
Avoid duplicated query when retrieving empty posts collections. Read more in #55677.
Post, Post Types improvements
In WordPress 6.1
WP_Posts_List_Table class will call
update_post_author_caches function in order to prime post author caches in a single database request. Read more in #56100.
A new filter
post_class_taxonomies will allow developers to reduce the number of taxonomies for which classes term classes are generated. Read more in #37114.
Sites running persistent object caching will have result of database queries in
_find_post_by_old_date functions, cached. Read more in #36723.
Additional build task
copy:block-json will convert and store all
block.json files in a single
blocks-json.php which will prevent all of this from happening for every block on each page load.
Trac ticket holding these changes: #55005.
Identifiers (such as Table and Field names) are escaped with the
%i placeholder which will prevent SQL Injection Vulnerabilities and provide a small performance improvement.
Trac ticket holding these changes: #52506.
Other performance improvements
WP_List_Table::get_column_info() is improved by adding the primary column to the cached header values (#34564).
In 6.1 wp-cron will be non-blocking for LiteSpeed LSAPI (#54668).
Retain default term option when unregistering taxonomies and adjustments to handling default terms for custom taxonomies (#54472).
Two new actions are wrapping the process of loading a template file (
wp_preload_resources enables resource preloading with
Prime user meta in WP_User_Query (#55594).
Thanks to @spacedmonkey, @tweetythierry, and @tillkruess for peer review.