Skip to content

Autoload max size - #5671

Closed
pbearne wants to merge 125 commits into
WordPress:trunkfrom
pbearne:autoload_max_size
Closed

pbearne wants to merge 125 commits into
WordPress:trunkfrom
pbearne:autoload_max_size

Conversation

@pbearne

@pbearne pbearne commented Nov 14, 2023

Copy link
Copy Markdown

Comment thread src/wp-includes/option.php Outdated
But this has broken the tests
But that said the new result may be right as the sizz override the value passed in
Comment thread src/wp-includes/option.php Outdated
Comment thread tests/phpunit/tests/option/option.php
Comment thread tests/phpunit/tests/option/option.php Outdated
Comment thread tests/phpunit/tests/option/wpAutoloadValuesToAutoload.php Outdated
Comment thread tests/phpunit/tests/option/wpAutoloadValuesToAutoload.php Outdated
Comment thread tests/phpunit/tests/option/wpAutoloadValuesToAutoload.php Outdated
Comment thread src/wp-includes/option.php Outdated
Comment thread tests/phpunit/tests/option/wpDetermineOptionAutoloadValue.php
Comment thread tests/phpunit/tests/option/wpAutoloadValuesToAutoload.php Outdated
Comment thread src/wp-includes/option.php Outdated
Comment thread tests/phpunit/tests/option/option.php Outdated
Comment thread tests/phpunit/tests/option/option.php Outdated

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me at this point. Thanks for all the iterations @pbearne!

@joemcgill joemcgill left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is looking great. Nice work @pbearne and @felixarntz. I've left a few comments, but nothing blocking. I think we can land this early and address new concerns as follow-up tasks.

Technically speaking, I do agree with @felixarntz's concern here, though I think it would be better to leave things as is for now, rather than creating the opportunity for unexpected values to be supported as "true" and wait for real bug reports to determine if we need to expand the checks in that switch statement.

Comment thread src/wp-includes/option.php Outdated
Comment thread src/wp-includes/option.php
Comment thread src/wp-includes/option.php
* @return string Returns the original $autoload value if explicit, or 'auto-on', 'auto-off',
* or 'auto' depending on default heuristics.
*/
function wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but I think the purpose of this function is not clear based on its name. I'd propose changing this to wp_normalize_option_autoload_value() instead. Happy to consider this in in a follow-up ticket if needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an @access private function anyway, so we could change the name later. Happy to reconsider in a follow up.

* @param string $option The passed option name.
* @param mixed $value The passed option value to be saved.
*/
$autoload = apply_filters( 'wp_default_autoload_value', null, $option, $value, $serialized_value );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, we're assuming the autoload value is undetermined (i.e., null), but that's not necessarily the case. That's probably fine, since we're already normalized and returned all of the supported values above, but could lead to unforeseen bug reports. I don't think we need to adjust anything, but wanted to flag for consideration.

@joemcgill

Copy link
Copy Markdown
Member

@felixarntz I left feedback on your comment in my PR review. But since that doesn't show up in Trac, I'll summarize:

Technically speaking, I agree but I think it would be better to leave things as is for now, rather than creating the opportunity for unexpected values to be supported as "true" and wait for real bug reports to determine if we need to handle other values.

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit-pick

Comment thread tests/phpunit/tests/option/option.php
Comment thread tests/phpunit/tests/option/option.php Outdated
@felixarntz

felixarntz commented Mar 22, 2024 •

Copy link
Copy Markdown
Member

@joemcgill Replying to your feedback:

Technically speaking, I do agree with @felixarntz's concern here, though I think it would be better to leave things as is for now, rather than creating the opportunity for unexpected values to be supported as "true" and wait for real bug reports to determine if we need to expand the checks in that switch statement.

I would generally agree with your assessment, but leaving this BC value handling out actually breaks previously existing unit tests. That to me is a reasonable indicator that we need to have this condition to convert technically unsupported values to true for BC. It doesn't really change whether or not this is a theoretical or practical concern, but we previously added tests ensuring those unsupported values evaluate as true, so I would feel uneasy about removing those tests.

LMKWYT.

@joemcgill

Copy link
Copy Markdown
Member

Ah, I had missed that there were previous tests breaking. In that case, I’d prioritize ensuring previous tests still pass, though it’s probably worth reviewing why the tests were written the way they were to see if they are unnecessarily broad

@felixarntz

Copy link
Copy Markdown
Member

@joemcgill Looking at the source of those tests, they are quite old, coming from https://core.trac.wordpress.org/ticket/31119 / https://core.trac.wordpress.org/changeset/31278.

Since at that time a boolean false ended up as 'yes', which certainly makes no sense, these tests were added which additionally assert that pretty much anything else does end up as 'yes'.

I don't feel strongly about the course of action here either way. I don't think there's realistically a great danger of changing those tests, because it's unlikely values like array() are passed to this function - why would someone do that? :) As always, I'm sure it happens but it's probably irrelevant talking at scale. More importantly, if we removed the BC handling, such an option would typically end up as auto, which would result in it still being autoloaded. So the only real "risk" from that change would be that the value is no longer considered explicit and thus could be overwritten by core at some point.

Concluding, I'd be okay removing the BC handling and adjusting the relevant tests to assert 'auto' instead of 'yes'. Let me know if you're still onboard with that given the additional context.

@joemcgill

Copy link
Copy Markdown
Member

@felixarntz I think I'm missing something. Looking at this PR, the test cases you're referencing don't seem to be changed (besides changing yes/no to on/off).

@felixarntz

Copy link
Copy Markdown
Member

@joemcgill That's my point. They aren't changed right now because the PR includes the extra BC handling. But if I remove that, they'll fail, so they'd need to be changed to expect 'auto' instead of 'on' ('yes' in legacy).

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joemcgill Below are the changes that would be needed to remove the BC handling.

Comment thread src/wp-includes/option.php Outdated
Comment thread tests/phpunit/tests/option/option.php
Comment thread tests/phpunit/tests/option/option.php Outdated
@joemcgill

Copy link
Copy Markdown
Member

@felixarntz

That's my point. They aren't changed right now because the PR includes the extra BC handling.

That's what I missed 😄 — I thought you were asking whether we should add some BC handling to this PR, not whether we should remove the BC handling that was already put in place. Thanks for clarifying.

I actually think I prefer the changes you've suggested above to handle unsupported values as if they were null and have them processed using the default logic (which functionally will still cause them to be autoloaded, so it's not really a BC). It could also be helpful to add a doing_it_wrong() where you previously had the BC logic to encourage developers to update their code to supported values.

Comment thread src/wp-includes/option.php
…provements.

Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com>
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Comment thread tests/phpunit/tests/option/wpDetermineOptionAutoloadValue.php Outdated

@joemcgill joemcgill left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest updates look good to me, @felixarntz.

@felixarntz

Copy link
Copy Markdown
Member

@felixarntz felixarntz closed this Apr 3, 2024
@sybrew

sybrew commented Dec 1, 2025

Copy link
Copy Markdown

I actually tested the goal of this PR.

My comments on the announcement post went ignored and bureaucratically buried. Yet the theoretical reasoning ("large autoload queries are slow") doesn't hold up under measurement.

Here are the results of 100 options of set size being added, with and without the default threshold set, the options cache is then cleared, and then again autoloaded + individually queried: message.15.txt.

Summary:

  1. Total execution time is virtually identical whether 0% or 100% of options are autoloaded

    • 140kb test: ~8.5ms average regardless of autoload %
    • 360kb test: ~21ms average regardless of autoload %
    • 1MB test: ~58ms average regardless of autoload %
  2. Autoload query time is negligible

    • Consistently 0.2-0.4ms across all tests
    • No meaningful increase when loading 100% vs 0% of options
    • Database caching renders the "large autoload query" concern moot
  3. The 150kb limit provides zero benefit

    • No measurable difference between 150kb and 100MB thresholds
    • Both configurations perform identically

The reasoning is simple:

  1. The database caches.
  2. PHP also caches, and memory long stopped being an issue since 7.0+.
  3. Not autoloading causes extra PHP and SQL work. get_option() is inefficient when it doesn't find an option in cache.

A lot of resources and time have been invested in discussing this and many related issues. It astounds me that no one has thought to benchmark this first. I'd have assumed that Core Performance, albeit spawned by individuals with zero experience in performant code, would've thought to benchmark changes before implementing them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants