DEV Community
WordPress autoloaded options: measure and review wp_options
Originally published at hamzaahmadaslam.com. How this article was made: drafted with AI assistance from a researched brief, then checked against primary documentation before publishing. Short answer: WordPress autoloaded options are rows in wp_options that WordPress loads into the alloptions array during a normal request. Measure the core autoload set, identify the largest rows and their owners, then disable autoload only for options that are not needed broadly. What WordPress autoloaded options do WordPress does not fetch every option with a separate query. The core wp_load_alloptions() function first checks the alloptions cache entry in the options cache group. If that entry is unavailable, it selects the options whose autoload values are considered loadable, builds one array, and caches that array as alloptions. Without a persistent object cache, the default WordPress object cache lasts only for the current request. A new PHP request therefore has to rebuild the cache when wp_load_alloptions() runs. With a persistent object cache, the alloptions array can persist between requests as one cache key. That distinction matters when reading a database profile. A persistent cache can remove repeated database reads for alloptions, but it does not make an oversized array free. WordPress still has to retrieve and work with the cached value when it is needed. For a wp_options autoload audit, measure what core treats as autoloaded. Do not assume that only rows containing yes count on current WordPress. What changed in WordPress 6.6 The WordPress 6.6 Options API dev note changed both the stored values and the default decision process. Existing yes and no rows were not migrated, so a current database can contain legacy and newer values together. The possible values you are likely to see are: yes: legacy value that is still treated as autoloaded. no: legacy value that is not autoloaded. on: an explicit autoload choice of true. off: an explicit autoload choice of false. auto: no explicit choice, with core deciding the default behavior. auto-on: a dynamically determined value that should autoload. auto-off: a dynamically determined value that should not autoload. Since WordPress 6.6, wp_autoload_values_to_autoload() returns yes, on, auto-on, and auto by default. The filter with the same name can remove values from that default set, but it cannot add arbitrary new values. WordPress 6.6 also changed the default handling of large option values. When WordPress determines autoload automatically, a serialized option value greater than the wp_max_autoloaded_option_size threshold is not autoloaded. The default threshold is 150,000 bytes, and the filter can change it per option. For a new option saved without an explicit choice, a value above that threshold is therefore not autoloaded by default. This rule does not mean every option larger than 150,000 bytes is forced off. Code that explicitly requests autoloading can still set an option to autoload. The size heuristic applies when WordPress is choosing the default. WordPress 6.6 also added the Site Health autoloaded options check. Its default threshold is 800,000 bytes through site_status_autoloaded_options_size_limit. Core reports the test as good below that limit and critical at the limit or above. Treat that value as a Site Health threshold, not as a promise that every site below it is fast. The useful question is which data is loaded on every request and whether that data needs to be there. How to measure WordPress autoloaded options with SQL For WordPress 6.6 and later, use the same default values that core treats as autoloaded. Replace wp_options if the site uses a different table prefix. Start with the total: SELECT
SUM(LENGTH(option_value)) AS total_bytes,
ROUND(SUM(LENGTH(option_value)) / 1024, 2) AS total_kb
FROM wp_options
WHERE autoload IN ('yes', 'on', 'auto-on', 'auto');
LENGTH() returns bytes for the stored option value. total_bytes gives you the raw total, while total_k...
Powered by Readybot.io
External Link
Platform
You are about to visit:
https://example.comThis will open in a new tab. Make sure you trust this link.