Performance with autoload and the options table

I didn’t find much information about how the autoloaded values are
used.

There is no special case for autoloaded options, they are used in the same way as else regular options, but lets figure out what autoload column of the options table means. This column determines do we need to fetch an option at the initialization stage of a request or should we fetch an option only on demand.

But when this autoloading happens and what function does it? All autoload options are loaded and cached by wp_load_alloptions function, which is called by is_blog_installed function at the beginning of each HTTP request, handled by WP.

Lets summarize: autoloaded option is the same option, but loaded at the beginning of HTTP request processing by WP.

Suppose I need to access an option … which method is recommended?

  1. It is bad approach to retrieve it from $GLOBALS directly, use get_option instead
  2. Globalize custom variables is not welcome and recommended to do it as less as possible
  3. From my point of view it’s the best option for you
  4. Even don’t think about something else 🙂

Why to use get_option function each time is the best option? Because:

  1. The first and the most important because: you can be confident that it will return up-to-date value, each time you call it.
  2. It will cache it for future reuse.
  3. It allows other plugin and theme to hook your option by hooking option_optionname filter.
  4. It will fetch an option if it is not loaded yet.

Leave a Comment