Make WordPress Core

Opened 7 months ago

Closed 6 months ago

Last modified 3 months ago

#61276 closed enhancement (fixed)

Add "Audit Autoloaded Options" Site Health Check

Reported by: mukesh27's profile mukesh27 Owned by: joemcgill's profile joemcgill
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: Site Health Keywords: has-patch has-unit-tests has-testing-info has-screenshots 2nd-opinion commit
Focuses: performance Cc:

Description (last modified by mukesh27)

The sites with many unnecessary autoloaded options face significant performance problems ( #54221, #42441 ). It's challenging for site owners to monitor and resolve these issues on their own, which can lead to suboptimal site performance and slower load times.

To address this, I propose adding a new "Audit Autoloaded Options" Site Health check to core. This would add a new test in the WordPress Site Health checks to monitor and report on the autoloaded options. This functionality helps in assessing and maintaining optimal site performance by providing insights into the number and size of autoloaded options.

An implementation of this Site Health check is already included in the Performance Lab plugin.

Key Features:

  • Integration with Site Health:
    • Adds a test under the Site Health section to monitor autoloaded options.
    • Displays the number and size of autoloaded options.
  • Status Indication:
    • Shows a 'good' status if the autoloaded options are within acceptable limits.
    • Shows a 'critical' status if the autoloaded options exceed the predefined threshold (default: 800,000 bytes), indicating a potential performance issue.
  • Customizable Threshold:
    • Introduces a filter (wp_autoloaded_options_limit_size_in_bytes) to adjust the threshold size for triggering warnings.

Attachments (2)

autoload feedback.jpg (81.5 KB) - added by krupajnanda 6 months ago.
critical error message.jpg (155.0 KB) - added by krupajnanda 6 months ago.

Download all attachments as: .zip

Change History (44)

#1 @mukesh27
7 months ago

  • Description modified (diff)

#2 @mukesh27
7 months ago

  • Milestone changed from Awaiting Review to 6.6
  • Owner set to mukesh27
  • Status changed from new to assigned

This ticket was mentioned in PR #6622 on WordPress/wordpress-develop by @mukesh27.


7 months ago
#3

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

#4 @joemcgill
7 months ago

  • Keywords changes-requested needs-testing added

Thanks, @mukesh27. This is a nice addition that will could pair well with r57920 which is set to ship in this release.

I'd like to get more eyes before committing and have left a few suggestions on the PR.

@mukesh27 commented on PR #6622:


6 months ago
#5

It seems like Tests with GB src and build is failing :x:

Cannot access this declaration file. You may need to run tsc again: /home/runner/work/wordpress-develop/wordpress-develop/src/wp-content/plugins/gutenberg/packages/core-data/build-types/index.d.ts

#6 @mukesh27
6 months ago

  • Keywords changes-requested removed

@joemcgill, thanks for the feedback. I have addressed those issues. The PR is now ready for review.

This ticket was mentioned in Slack in #core-test by mukeshpanchal27. View the logs.


6 months ago

#8 follow-up: @krupajnanda
6 months ago

@mukesh27

Could we show the things with bullet pointers which are the main high lighters?

E.g. Instead of Your site has 118 autoloaded options (size: 25 KB) in the options table, which is acceptable. shouldn't we show something like this?

  • Your site has 118 autoloaded options
  • The size is 25KB
  • Is acceptable? Yes/No (What ever the status)

Also, it does not show Status Indication as you have explained in the issue description. Please confirm if I missed any thing or should it be checked elsewhere?

Please check the attched screenshot.

#9 in reply to: ↑ 8 @mukesh27
6 months ago

Replying to krupajnanda:

Could we show the things with bullet pointers which are the main high lighters?

With the site health check, we are going to provide some information to the site author. Including a paragraph makes sense for this purpose. I don't oppose for the bullet point.

Also, it does not show Status Indication as you have explained in the issue description. Please confirm if I missed any thing or should it be checked elsewhere?

Critical status: If the autoload options size exceeds the limit (in our case, 800000), the test fails and displays a critical error. Refer to the first image in this https://github.com/WordPress/wordpress-develop/pull/6622#pullrequestreview-2078097626. To test this scenario in a fresh WordPress installation, use the filter shown in the PR comment.

Good status: If the autoload options size is below the limit (in our case, 800000), the test passes. Refer to the last image in this https://github.com/WordPress/wordpress-develop/pull/6622#pullrequestreview-2078097626.

#10 @pooja1210
6 months ago

Hi,

Test Report
Patch - https://github.com/WordPress/wordpress-develop/pull/6622

Environment:
OS: Mac
WordPress: 6.6-alpha
PHP: v8.1
Browser: Mac

Expected Result: The test under the Site Health section for the autoloaded option is visible properly. However, I tried adding the wp_autoloaded_options_limit_size_in_bytes filter inside MU plugin but it didn't show the critical status to me.

Screenshot:
https://prnt.sc/nDfdjJ7SI00j

Thanks

#11 @Ankit K Gupta
6 months ago

Test Report ✅

This new enhancement works as expected in my test.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/6622

Environment

  • WordPress: 6.6-alpha-20240527.194552
  • PHP: 8.3.0
  • Server: nginx/1.16.0
  • Database: mysqli (Server: 5.7.28 / Client: mysqlnd 8.3.0)
  • Browser: Chrome 124.0.0.0
  • OS: macOS
  • Theme: Twenty Sixteen 3.2
  • MU Plugins:
    • Autoloaded Options Limit Disabler 1.0

Actual Results

  • ✅ Enhancement works fine with purposeed PR.

Additional Notes

When autoloaded options exceed the predefined threshold:

https://i.imgur.com/zFkLC8r.jpeg

When autoloaded options are within acceptable limits.

https://i.imgur.com/pT6rzg1.jpeg

#12 @krupajnanda
6 months ago

@mukesh27 Please check the report mentioned below.

Test Report

Patch tested: https://github.com/WordPress/wordpress-develop/pull/6622

Environment

  • WordPress: 6.6-alpha-57778-src
  • PHP: 8.2.15
  • Server: nginx/1.25.3
  • Database: mysqli (Server: 8.0.36 / Client: mysqlnd 8.2.15)
  • Browser: Chrome 124.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Four 1.1
  • MU Plugins:
    • autoload-checker.php
  • Plugins:
    • Test Reports 1.1.0

Expected Result :

It should show critical if I add below filter in my mu plugin.

add_filter( 'wp_autoloaded_options_limit_size_in_bytes', '__return_zero' );

Actual Results

I am not able to replicate the "Critical Issue" for autoloader. ❎

Additional Notes

  • I tried couple of different values with this filter but unable to replicate the expected result. Every time it shows only Autoloaded options are acceptable.


add_filter( 'wp_autoloaded_options_limit_size_in_bytes', '__return_zero' );

Last edited 6 months ago by krupajnanda (previous) (diff)

This ticket was mentioned in Slack in #core-test by krupajnanda. View the logs.


6 months ago

#14 @krupajnanda
6 months ago

  • Keywords has-testing-info added

#15 @mukesh27
6 months ago

Thanks @pooja1210 and @krupajnanda for testing. In recent review feedback i have updated the filter name so update filter is:

add_filter( 'site_status_autoloaded_options_size_limit', '__return_zero' );

#16 @krupajnanda
6 months ago

  • Keywords has-screenshots added

@mukesh27 Thank you for sharing the updated filter and after trying with that I am able to replicate the expected result. Please check the report attached below.

Test Report

Description

This report validates whether the indicated patch works as expected. ✅

Patch tested: https://github.com/WordPress/wordpress-develop/pull/6622

Environment

  • WordPress: 6.6-alpha-57778-src
  • PHP: 8.2.15
  • Server: nginx/1.25.3
  • Database: mysqli (Server: 8.0.36 / Client: mysqlnd 8.2.15)
  • Browser: Chrome 124.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Four 1.1
  • MU Plugins:
    • Safe Autoloaded Options Limit Test (MU Plugin) 1.0
  • Plugins:
    • Test Reports 1.1.0

Actual Results

  1. ✅ Issue resolved with patch.

Supplemental Artifacts

Add as Attachment

Last edited 6 months ago by mukesh27 (previous) (diff)

#17 @Ankit K Gupta
6 months ago

  • Keywords has-screenshots removed

Hello @krupajnanda @pooja1210, I was able to generate a Critical Issue by updating the threshold in database.
When I change the value with below query, critical issue was appearing on Site Health section.

INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('test_large_option', REPEAT('a', 800000), 'yes');

#18 @Ankit K Gupta
6 months ago

  • Keywords has-screenshots added

#19 @mukesh27
6 months ago

  • Keywords needs-testing removed

Thanks for testing folks.

All ✅ per the tests reports.

#20 @krupajnanda
6 months ago

  • Keywords needs-testing added

@ankit-k-gupta Thank you for sharing the details. I am able to replicate the expected behaviour now with the help of the newly shared filter. 🙌

#21 @krupajnanda
6 months ago

  • Keywords needs-testing removed

#22 @pooja1210
6 months ago

Hi @mukesh27,

I have verified the recent changes and those are working fine. Here's the test report for the same.

Test Report

Patch tested - https://github.com/WordPress/wordpress-develop/pull/6622/commits/026182b6e4e7da237fb90d15d4d104a3c0a7f14f

Environment:
OS: Mac
WordPress: 6.6-alpha
PHP: v8.1
Browser: Chrome v125
MU Plugins: Increase autoload options limit

Results: The changes are working fine. Test under the Site Health section for the autoloaded option is visible properly and if the autoload limit is exceeded the test falls and a critical error is visible.

Screenshot
Critical Status: https://prnt.sc/pvVVGBzy_sbY
Good status: https://prnt.sc/nDfdjJ7SI00j

Thanks

#23 @johnbillion
6 months ago

  • Keywords 2nd-opinion added

Is this health check actionable by an end user?

Let's say I run the health check and everything is ok except for the message saying "Autoloaded options could affect performance". The message essentially suggests deleting some options from the options table. The handbook page that it links to says "For step-by-step instructions on viewing and changing autoloaded options, check with your hosting provider" which is questionable.

If I see this message on my site, what am I actually going to do with it?

This ticket was mentioned in Slack in #core-performance by joemcgill. View the logs.


6 months ago

#25 @oglekler
6 months ago

I have doubts about the phrase: "You can reduce the number of autoloaded options by cleaning up your site's options table". I had an experience (with another CMS I don't like at all) when I've told the manager not to store images into the public_html folder, and she deleted everything from it except subfolders to make things pretty. 🙈 So, taking this phrase as it is, a person can go into the database and truncate the options table. Btw, not loading some options can damage performance too because they will be loaded one by one when needed. And, am I right in thinking that not autoloaded transients are taking two trips into the database? 🤔

I believe that the correct way is to notify the user about the problem, with note that this issue should be handled by the developer.

This information will be useful for developers to pay attention to, it is very convenient to have it usually as a site maintainer you are not thinking about such things (expecting that theme or plugins developers are known what they are doing). Possibly it could be added to the Directories and Sizes panel of the Info tab. This also can bring attention of themes and plugins developers to what they are autoloading. "To load or not to load" can be a tough decision 🙂

#26 @mukesh27
6 months ago

Thanks, @johnbillion and @oglekler, for your thoughts.

Is the phase a blocker for this health check? I would like to update it as below. Let me know what you think.

Before:
Autoloaded options are configuration settings for plugins and themes that are automatically loaded with every page load in WordPress. Having too many autoloaded options can slow down your site. Your site has xyz autoloaded options (size: xx KB) in the options table, which could cause your site to be slow. You can reduce the number of autoloaded options by cleaning up your site's options table.

After:
Autoloaded options are configuration settings for plugins and themes that are automatically loaded with every page load in WordPress. Having too many autoloaded options can slow down your site. Your site has xyz autoloaded options (size: xx KB) in the options table, which could cause your site to be slow. It is advisable to have a developer review and clean up these options to prevent potential slowdowns.

#27 @oglekler
6 months ago

@mukesh27 I think, proposed phrase with an advice to get a developer on this task is good enought. Let's found out what John thinks. This is quite important information to have in the Health Check 🚀

#28 @joemcgill
6 months ago

While I appreciate the intent to help users not harm there site, I don't particularly like the insinuation that people aren't capable of reviewing documentation and deciding for themselves whether they need to contact someone to assist them with a site maintenance task.

I'd suggest saying something like:

Autoloaded options are configuration settings for plugins and themes that are automatically loaded with every page load in WordPress. Having too many autoloaded options can slow down your site. Your site has xyz autoloaded options (size: xx KB) in the options table, which could cause your site to be slow. You can review the options being autoloaded in your database and remove any options that are no longer needed by your site.

We also already include a link to https://developer.wordpress.org/advanced-administration/performance/optimization/#autoloaded-options with some follow-up instructions, which we can probably improve further.

@mukesh27 commented on PR #6622:


6 months ago
#29

Thanks, @costdev, for the feedback.

@joemcgill, I have updated the copy content.

#30 @joemcgill
6 months ago

  • Keywords commit added
  • Owner changed from mukesh27 to joemcgill

I'm marking this for commit consideration and will handle this prior to the beta 1 code freeze tomorrow unless someone beats me to it or there is new info that would suggest not including this check in 6.6

#31 @joemcgill
6 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 58332:

Site Health: Add test for large autoloaded options.

This adds a new Site Health check that will alert site owners if they are autoloading a large amount of data from the options table, as it could result in poor performance. The issue will be shown if the size of autoloaded options is greater than 800 KB, which can be adjusted using the new site_status_autoloaded_options_size_limit filter.

Props mukesh27, joemcgill, rajinsharwar, costdev, audrasjb, krupajnanda, pooja1210, Ankit K Gupta, johnbillion, oglekler.
Fixes #61276.

#33 @westonruter
6 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

@joemcgill I think the commit is missing the hardening fix from https://github.com/WordPress/performance/pull/1238

Last edited 6 months ago by westonruter (previous) (diff)

This ticket was mentioned in Slack in #core-performance by clarkeemily. View the logs.


6 months ago

#35 @joemcgill
6 months ago

  • Type changed from enhancement to defect (bug)

Thanks @westonruter. Let's address that fix during beta. I'm going to temporarily change this to a bug until the beta release is done to not block the release process.

@mukesh27 commented on PR #6725:


6 months ago
#37

@westonruter I have open PR that account that issue. cc. @joemcgill

#38 @joemcgill
6 months ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 58338:

Site Health: Ensure each alloptions value is serialized.

This adds additional hardening to the Autoload options Health Check to avoid potential bugs when extenders return unserialzed values from wp_load_alloptions().

Follow-up to [58332].

Props mukesh27, joemcgill, westonruter.
Fixes #61276.

#39 @joemcgill
6 months ago

  • Type changed from defect (bug) to enhancement

Setting this back to an enhancement ticket now that 6.6 Beta 1 has been shipped to reflect to correct type.

#41 @desrosj
6 months ago

In 58408:

Coding Standards: Apply changes after running composer format.

This applies several formatting related changes made while running composer format.

Follow up to [55720], [58171], [58271], [58282], [58283], [58292], [58299], [58303], [58332].
See #51857, #60719, #60895, #61021, #61118, #61228, #61276, #61324.

This ticket was mentioned in Slack in #forums by macmanx. View the logs.


3 months ago

Note: See TracTickets for help on using tickets.