Skip to content

WordPress autoload audit — finding the 100MB option loading on every request

Bloated autoloaded options silently inflate every PHP request. Here is how to find the culprit, decide what to keep, and prevent the next plugin from doing it again.

The site has been getting slower for months. TTFB on /wp-admin/ is now over four seconds even with object cache warm. top shows PHP-FPM workers eating memory at request start, before any template renders. You strace one worker and it spends 1.6 seconds in mysqli_real_query on a single query against wp_options — the autoload query that runs on every WordPress bootstrap.

What’s happening

WordPress loads every option flagged autoload='yes' into memory at the start of every request. The alloptions cache key is a single serialized PHP array that holds the whole pile, so the cost is bytes-read + unserialize + memory footprint on every PHP-FPM worker, every page view, every wp-cron tick, every AJAX call.

The original design assumed autoloaded options were small strings: site URL, active theme, timezone. Plugins broke that assumption by stashing large blobs there:

  • Migration plugins that serialize search-and-replace logs into options and never clean them up
  • Analytics plugins that buffer pageview batches into a single option key
  • Cache plugins that write their “warm cache” inventory into autoload
  • Form plugins that store every submission’s transient state with autoload='yes' by mistake
  • Old removed plugins that left options behind without flipping autoload off

We have seen single options exceed 80MB on production sites — a 4MB option is already too big, anything over 1MB deserves scrutiny. The query that fetches autoload data is SELECT option_name, option_value FROM wp_options WHERE autoload='yes' and it has no LIMIT clause. There is no path to “just load less of it.”

The other quiet failure mode: total autoload size that looks reasonable (say 3MB) but with thousands of rows. The unserialize cost on a giant PHP array is non-linear; 12,000 small options is worse than 300 medium ones for the same total bytes.

How to verify

Total autoload weight and row count first:

wp db query "SELECT SUM(LENGTH(option_value))/1024/1024 AS mb_total, COUNT(*) AS row_count FROM wp_options WHERE autoload='yes'"

Anything past 1MB or 1,500 rows on a single-site install is worth investigating. Now find the top offenders:

wp db query "SELECT option_name, LENGTH(option_value)/1024 AS kb FROM wp_options WHERE autoload='yes' ORDER BY LENGTH(option_value) DESC LIMIT 25"

You will usually see five to ten options dominating the total. Identify which plugin owns each one. For options that look orphaned (prefix matches a plugin that is no longer installed), confirm:

wp plugin list --status=active --format=csv | cut -d, -f1
wp option get <suspicious_option_name> | head -c 2000

If the option contains a serialized PHP structure you can read with wp option pluck to drill into sub-keys without dumping the whole blob into your terminal.

For long-tail row count problems, group by plugin prefix:

SELECT
  SUBSTRING_INDEX(option_name, '_', 2) AS prefix,
  COUNT(*) AS row_count,
  SUM(LENGTH(option_value))/1024 AS kb_total
FROM wp_options
WHERE autoload='yes'
GROUP BY prefix
ORDER BY row_count DESC
LIMIT 30;

Run this from wp db query --skip-column-names or directly in your client. The prefix usually maps one-to-one to the plugin slug.

Finally, time the actual query against production:

wp db query "SET profiling = 1; SELECT option_name FROM wp_options WHERE autoload='yes'; SHOW PROFILES;"

If the query takes longer than 100ms you are paying that cost on every PHP request.

The fix

Three steps, in this order: flip autoload off on the heavy options, prune orphaned rows, then prevent recurrence.

Flip autoload off. For options the plugin still needs but does not need on every request:

wp option set --autoload=no <option_name>

Or do it for an entire list:

wp db query "UPDATE wp_options SET autoload='no' WHERE option_name IN ('plugin_x_log','plugin_x_inventory','plugin_y_buffer')"
wp cache flush

The cache flush matters — alloptions is cached and stale until invalidated. If you are running an object cache (Redis, Memcached) flush there too.

Prune orphaned options from removed plugins. Confirm the plugin is truly gone, then:

wp db query "DELETE FROM wp_options WHERE option_name LIKE 'oldplugin\\_%' OR option_name LIKE '\\_transient\\_oldplugin\\_%'"

Be deliberate with LIKE patterns — escape underscores in MySQL LIKE strings because _ is a wildcard. The \\_ form keeps it literal.

Prevent the next plugin from dumping into autoload. Add a small mu-plugin under wp-content/mu-plugins/sh-autoload-guard.php:

<?php
/**
 * Stack Harbor — Autoload guard
 * Refuses to autoload any option over 256KB and logs the attempt.
 */
add_filter('pre_update_option', function ($value, $option, $old_value) {
    static $limit = 262144; // 256KB
    if (strlen(maybe_serialize($value)) > $limit) {
        global $wpdb;
        $wpdb->update($wpdb->options, ['autoload' => 'no'], ['option_name' => $option]);
        error_log(sprintf('[autoload-guard] %s exceeded %d bytes — autoload disabled', $option, $limit));
    }
    return $value;
}, 10, 3);

This does not prevent the option from being written — it prevents it from being autoloaded. The plugin still works; it just pays for its own read.

After the cleanup, re-measure. The autoload query should drop to under 30ms and PHP-FPM RSS should shrink by tens of MB per worker, which compounds across the pool.


Stack Harbor runs WordPress estates under the enterprise WordPress support operating model — autoload audits, plugin inventory, and database hygiene are part of the standard onboarding. If your wp_options table has been growing unmonitored for years, we will audit it.