WordPress

WordPress 6.1 Brings Significant Boost to Database Performance

WordPress 6.1, set for release in November 2022, will bring a significant enhancement to database performance due to new post query caching.

This feature promises to boost the speed of WordPress websites.
The specific improvement is centered on post query caching.

In a Twitter thread announcing this, someone inquired if the improvement had already been launched in version 6.0.

Massive Improvement

A WordPress core contributor involved in this project claimed the caching feature will lead to a dramatic performance boost.

The core contributor tweeted:

"In WordPress 6.1, there is a massive improvement to database performance.
Database queries in WP_Query are now cached. A ticket I have been working on for 5+ years was merged.
This should result in billions of fewer repeated database queries."

A draft development note was also created, offering more details about the cache:

"WordPress 6.1 includes an improvement to how database queries are performed in the ‘WP_Query’ class so that the result of database queries will be cached in object caching.
This means that if the same database query is run more than once, the result will be loaded from cache.
For those using persistent object caching, this will mean that until caches are invalidated, the database query will not be run again, resulting in far fewer queries to the database."

They asked:

"Thanks! Wasn’t there an improvement already in 6.0?
With that, we had major issues on big woo-stores: disappearing categories on archive pages when only child categories are checked, not the top-level (parent) category.
Curious about the note with more context."

The WordPress core committer responded:

"We improve database performance all the time.
There was an improvement to term query caching in 6.0. This is post query caching. Related but not the same.
That issue was patched in 6.0.1. I patched it myself."

WordPress Database and Queries

WordPress stores different parts of a website in a database organized into tables. For instance, webpage content is stored in a table. When someone visits a page, WordPress "queries" the database to find this content.

WordPress makes multiple queries to the database for every requested page and does so for each site visitor. This can burden the server, especially if it happens thousands of times per minute, leading to slower database performance and an overall slow site.

With the new database caching feature, WordPress will first check the cache for information before making a database query, analogous to immediately retrieving a pre-prepared order instead of waiting for it to be made.

Response from the WordPress Community

The announcement was well-received by the community. Here are some reactions:

"Congrats. Such a huge impact."
— Elie Sloïm

"Fair play to you, this is huge in many aspects. Cannot wait to try this out. Many, many thanks for all your hard work and persistence!"
— Simon Pollard

"Nice one, Jonny! Very cool that you can have a positive impact at that scale."
— Keith Devon

"Brilliant! Always bugged me you had to jump through hoops to avoid duplicate queries with this."
— Jon Brown

Last Minute Issues Getting Fixed

Despite the enthusiastic tweet, a last-minute issue arose, casting doubt on whether this feature would make it into the next WordPress release. The GitHub ticket for the cache project was initially closed, indicating that all bugs were resolved. However, it was reopened later due to new issues related to persistent Object Caching.

The developer explained:

"Reopening, as I have discovered a couple of issues when persistent Object Caching.
Issue 1 – Cache add is called a lot when persistent Object Caching is enabled. This is because update_post_caches is called. This function should not be called when object cache is enabled.
Issue 2 – Cache set is called every WP_Query run, not only the first."

A new GitHub pull request was opened to document the fixes for these issues.

Confirmed: Database Cache Will Be in WordPress 6.1

I contacted the developer, and he assured me that there would be no delay. He confirmed that with six weeks left until the release, the newly discovered issues would be fixed, and the new caching feature would be included in WordPress 6.1.

Updated Status

Several days later, the GitHub pull request for this feature was updated to state that the issues have been resolved.

The comment noted:

"Query: Save excessive cache add and sets in WP_Query.
In [53941] database query caching was added to WP_Query. However, on sites with persistent object caching enabled, this resulted in a high number of unnecessary cache set and adds being run on every request. Caches are not set if the query cache already exists and is cached. Replace usage of update_post_caches with _prime_post_caches to ensure that only posts that are not in cache are primed."

Following this, the core contributor noted:

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

While there hasn’t been an official announcement yet, this is not unusual. Each release contains numerous improvements, with the most significant highlighted on the release day.

Expect the new feature to improve WordPress performance in version 6.1, set for November 2022.


Featured image by Shutterstock/iViDI Studio

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button