WordPress 6.1 Contains “Massive Improvement To Database Performance”

WordPress 6.1 Contains “Massive Improvement To Database Performance”


WordPress 6.1, scheduled for November 2022, will feature a “massive improvement to database performance” thanks to new post query caching.

This new feature promises to make WordPress websites perform faster.

The exact caching improvement is to the post query caching.

In the Twitter thread announcement someone asked if this improvement was already launched in version 6.0.

Massive Improvement

According to the WordPress core contributor who worked on this project, the caching feature will result in a dramatic improvement.

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 less repeated database queries”

A draft dev note was also begun containing more information 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 who are using persistent object caching, this will mean that until caches are invalidated, the database query will not be run again, resulting in far few 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 archives pages when only child categories are checked, not the top level (parent) categorie.

Curious about the note with more context”

The WordPress core committer responded:

“We are improve database performance all the time.

There was improved 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 various parts of the website in a database.

A database contains information about the site organized into tables.

For example, all of the content for webpage posts are stored in a table.

When someone visits a webpage, WordPress will “query” the database to search and find the content for that webpage in the database.

WordPress makes multiple queries to the database for every requested webpage and does it for every site visitor.

Consequently that can become a heavy load on a server when it happens thousands of times per minute, resulting in slower database performance which in turn slows down the entire site.

With this new database caching feature, instead of making a database query it will instead first check if what it’s looking for is in a cache and pull the information from there.

It’s analogous to placing an order for lunch and instead of having to wait for the lunch to be made, the order taker reaches beneath the counter and produces it right away.

Response from the WordPress Community

The unofficial announcement was enthusiastically received.

Last Minute Issues Getting Fixed

Despite the enthusiastic tweet announcing that this feature will be in the next WordPress release,  a  last minute issue arose that seemed to cast doubt on whether  this feature will make it into the next WordPress release.

The GitHub ticket for the cache project was closed, meaning that all the bugs seemed to be worked out and it was finished.

But hours later the same WordPress contributor reopened the ticket because new issues were discovered.

The problem that was discovered had to do with persistent Object Caching.

They wrote an explanation:

“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 release was opened to document the fix for the newly discovered issues.

Confirmed: Database Cache Will Be in WordPress 6.1

I reached out to the developer via direct message on Twitter and he responded that there will not be a delay.

He confirmed that as of today there are six weeks left and these newly discovered issues will be fixed and the new caching feature will be included in WordPress 6.1.

Updated Status

Several days later the GitHub pull release for this feature was updated to note 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.”

Then immediately following that comment the core contributor noted:

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

Nothing has been officially announced yet but that’s not unusual. Every release contains hundreds of improvements and the most important are generally highlighted on the actual day of release.

Expect the new feature that will improve WordPress performance to land in version 6.1, currently scheduled for November 2022.

Featured image by Shutterstock/iViDI Studio


Source link