[wp-trac] [WordPress Trac] #42441: Disable autoload for large options

WordPress Trac noreply at wordpress.org
Wed Apr 3 21:29:29 UTC 2024


#42441: Disable autoload for large options
-------------------------------------------------+-------------------------
 Reporter:  markjaquith                          |       Owner:  flixos90
     Type:  enhancement                          |      Status:  closed
 Priority:  normal                               |   Milestone:  6.6
Component:  Options, Meta APIs                   |     Version:
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests early       |     Focuses:
  commit                                         |  performance
-------------------------------------------------+-------------------------
Changes (by flixos90):

 * status:  reviewing => closed
 * resolution:   => fixed


Comment:

 In [changeset:"57920" 57920]:
 {{{
 #!CommitTicketReference repository="" revision="57920"
 Options, Meta APIs: Use more sensible default for autoloading options
 which allows WordPress core to make a decision.

 An excessive amount of autoloaded options is a common cause for slow
 database responses, sometimes caused by very large individual autoloaded
 options. As it is not mandatory to provide an autoload value when adding
 an option to the database, it tends to be ignored, which in combination
 with a default value of "yes" and lack of documentation can lead to the
 aforementioned problem.

 This changeset enhances the option autoloading behavior in several ways:
 * Update the function documentation to encourage the use of boolean `true`
 or `false` to explicitly provide an autoload value for an option.
 * Use new string values `on` and `off` for explicitly provided values
 stored in the database, to distinguish them from `yes` and `no`, since
 `yes` does not allow determining whether it was set intentionally by the
 developer or only as a default.
 * Effectively deprecate the values `yes` and `no`. They are still
 supported for backward compatibility, but now discouraged.
 * Use `null` as new default autoload value for `add_option()`. If the
 developer does not provide an explicit value, this will now trigger
 WordPress logic to determine an autoload value to use:
     * If WordPress determines that the option should not be autoloaded, it
 is stored in the database as `auto-off`. As part of this changeset, the
 single heuristic introduced for that is to check whether the option size
 is larger than a threshold of 150k bytes. This threshold is filterable via
 a new `wp_max_autoloaded_option_size` filter.
     * If WordPress determines that the option should be autoloaded, it is
 stored in the database as `auto-on`. No logic to make such a decision is
 introduced as part of this changeset, but a new filter
 `wp_default_autoload_value` can be used to define such heuristics, e.g. by
 optimization plugins.
     * If WordPress cannot determine whether or not to autoload the option,
 it is stored in the database as `auto`.
     * This effectively means that any option without an explicit autoload
 value provided by the developer will be stored with an autoload value of
 `auto`, unless the option's size exceeds the aforementioned threshold.
 Options with a value of `auto` are still autoloaded as of today, most
 importantly for backward compatibility. A new function
 `wp_autoload_values_to_autoload()` returns the list of autolaod values
 that dictate for an option to be autoloaded, and a new filter
 `wp_autoload_values_to_autoload` can be used to alter that list.

 These behavioral changes encourage developers to be more mindful of
 autoloading, while providing WordPress core and optimization plugins with
 additional control over heuristics for autoloading options where no
 explicit autoload value was provided.

 At the same time, the changes are fully backward compatible from a
 functionality perspective, with the only exception being that very large
 options will now no longer be autoloaded if the developer did not
 explicitly request for them to be autoloaded. Neither WordPress core nor
 plugins are able to override an explicitly provided value, which is
 intentional to continue giving developers full control over their own
 options.

 Props pbearne, flixos90, joemcgill, azaozz, spacedmonkey, swissspidy,
 mukesh27, markjaquith.
 Fixes #42441.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/42441#comment:77>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list