Tip 9: Optimize your database

Performance Tip 9 is to Optimize your WordPress database
– server do less.

In my experience I rarely have a problem with database performance. The elapsed query time is a fraction of the server response. Even in sites with thousands of posts.

PageQuery time ( # ) ElapsedHooksFiles
Home0.010022640228271 ( 21 )0.22641915913391
Elementor0.044546365737915 ( 90 )6.852413850333404
Big images0.036091566085815 ( 94 )5.108721 858783345
webp images0.044345617294312 ( 96 )3.002667858843345
About0.00510573387146 ( 13 )0.16217013805383

There are exceptions. With a large database some queries take a long time to run. Especially those accessing the wp_postmeta table performing a match on the meta_value.

Trace shutdown report

The above information was gleaned from the trace shutdown report, produced by oik-bwtrace.

About page

<!--PHP version:8.0.15
--><!--PHP functions:2005
--><!--User functions:3416
--><!--Registered widgets:29
--><!--Post types:14
--><!--Query time:0.00510573387146
--><!--Trace file:
--><!--Trace records:
--><!--Trace errors:
--><!--Hook count:13805
--><!--Remote addr:
--><!--Elapsed (secs):0.162170

Elementor ( another invocation )

<!--PHP version:8.0.15
--><!--PHP functions:2005
--><!--User functions:6112
--><!--Registered widgets:71
--><!--Post types:40
--><!--Query time:0.044870615005493
--><!--Trace file:
--><!--Trace records:
--><!--Trace errors:
--><!--Hook count:85147
--><!--Remote addr:
--><!--Elapsed (secs):8.279563

There’s probably a formula that can be used to determine the expected server response based on the number of each of the counts reported. Notice that the figure for Plugins: is the same for both requests. It shows the total number of plugins that WordPress would have loaded were it not for oik-unloader.