Introduction
In WordPress, the options table is a critical component of the database that stores various settings and configuration options for the site. This table includes a wide range of data such as site URLs, active theme information, plugin settings, and other miscellaneous preferences. Each entry in the options table consists of four key fields: option_id, option_name, option_value, and autoload. The option_name field holds the name of the option, while option_value contains its corresponding value, which can be of various data types. The autoload field specifies whether the option should be automatically loaded with every page request. Options marked as ‘autoload’ are loaded into memory on every page load, which can impact performance if there are too many such options.
How Can I Check the Size of The Autoloaded Options?
There are several ways of checking the size of all options that your site autoloads. The two most common ones we see on our platform are using phpMyAdmin and the WP CLI tools that are available by default on your Bolt.
Using phpMyAdmin
After logging in to phpMyAdmin for your database, select the database your site is using on the left-hand side. After that, you can run the following query to get an overview of all the autoloaded options sorted by size:
SELECT option_name, length(option_value) AS option_value_length FROM wp_options WHERE autoload='yes' ORDER BY option_value_length DESC;
If you want to see the total size instead, you can use this query:
SELECT SUM(LENGTH(option_value)) as autoloaded_options_size FROM wp_options WHERE autoload='yes';
This last query will get you output such as:
The value for autoloaded_options_size is in Bytes. In the example above, that would mean it’s 45.9KB in size.
Using WP-CLI
Using WP-CLI we can use one of the built-in toolsets to get an overview of the total size quickly. The command for that would be: wp doctor check autoload-options-size
Which gives you an output similar to this:
When Should I Clean The Autoloaded Options Up?
Of course, smaller is always better in this case. But a general rule of thumb is to keep the total size of the autoloaded options below 1MB. This might seem to be on the low end, but keep in mind that all of these are loaded on every request that hits the site. So for example, if your autoloaded options size is 20MB it would mean that with 1000 simultaneous visitors, the site would need 20GB of memory allocated to keep working.
How Can I Clean The Autoloaded Options Up?
If you’ve analysed all the autoloaded options, you will find two distinct categories that you can safely eliminate without harming your performance.
The first is autoloaded options set by already-removed plugins or themes. Yes, they should have been removed when uninstalled, but unfortunately, that doesn’t always happen. These are the easiest ones, as we can just safely delete them.
The second one is autoloaded options that are not really needed on every page. Some plugins set all their options to be autoloaded for convenience or maybe even the appearance of being performant. After all, who doesn’t want their plugin to be performant, right? As this kills the scalability of your site, you can disable these. Keep in mind, though, that depending on the update process, some of these might be set back to being autoloaded after updates. So ensure you check this every now and then.
Warning: Always make a backup of your database before making any changes. In theory, nothing should go wrong or break. In practice, everything will break down at the most inconvenient moment. So we highly recommend you take a database backup before proceeding with the following steps.
Using phpMyAdmin
If it is deleting a single option we want to do, we first need to open the wp_options table. Locate the option you wish to remove and click on the Delete option next to the option id:
Switching up a single item from being autoloaded to not being autoloaded is a matter of double-clicking on the column marked as autoloaded. Switch the option from ‘yes’ to ‘no’ and press enter:
Using WP-CLI
Again, deleting an entire option is the simplest. We do this by issuing the following command. Make sure to substitute the ‘deletable_option’
text to the option you want to delete:
$ wp option delete deletable_option
Success: Deleted 'deletable_option' option.
If all goes well, you will receive the Success message stating that everything went correctly.
If we are looking to update a single option from being autoloaded to that not being the case, we can use the following command. Again, substitute ‘option_to_update’
to whatever option you are changing:
$ wp option set-autoload option_to_update no
Success: Updated autoload value for ‘option_to_update’ option.
Conclusion
Autoloaded options are like a two-edged sword. On one hand, they can improve the performance of your site. On the other hand, they can also greatly affect the scalability of your site in a negative way. So having them present is not a problem per se, but it’s good to keep the amount and size of them limited. Using the techniques described above you can determine which options are autoloaded and you can limit the amount of them as well. If you are interested in improving the performance and scalability of your site, a good method of achieving that could be using our Accelerated Domains.