Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a quick and dirty plugin unloader for performance improvements #1

Open
bobbingwide opened this issue Oct 23, 2021 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Oct 23, 2021

Background

  • Users install and activate plugins in order to provide additional functionality
  • These plugins can slow the site down because:
    • They add processing in the server
    • They add processing in the browser
  • It's often the case that for some URLs this work is unnecessary; the URL would work correctly even if the plugin is not active.
  • We need a way to make the website faster while still providing the required functionality where it's needed.

Observations & assumptions

  • Some websites are structured so that certain plugins can be deactivated on specific pages / URLs
  • By not activating a plugin on these pages / URLs we can improve the performance of both the server and browser
  • The main problem with deactivating a plugin is when it's definitely needed some of the time.
    eg WooCommerce is needed for shop/store, product display, product category display etc.
  • It's probably just as easy to deactivate a plugin as it is to activate one

Requirement

  • Fast server side processing for reduced Time To First Byte
  • Fast loading in the browser
  • Reduce number of bytes returned to the browser
  • Reduce number of files to load
  • Reduce JavaScript processing
  • Highly configurable
  • Should not affect cacheing

Proposed solution

Load the required plugins only

  • Implement a WordPress Must Use plugin that will
  • determine which plugins can be dynamically deactivated
  • for a particular subset of URLs
  • Implement a filter hook for the option_active_plugin filter to remove these plugins from list of plugins to activate

Administration

  • Provide an admin interface to allow the plugins to be deactivated to be selected
  • Allow the MU logic to be enabled and disabled

Considerations

  • It will require an admin interface to allow the advanced user / developer to choose which plugins to deactivate for each particular URL.
  • The interface will need to cater for different forms of archive URL.
  • Whether or not the configuration is stored in the database or a flat file is to be determined.
  • For ease of implementation a flat file will do the job initially.
  • The logic will be a simpler version of the oik-loader plugin, performed in reverse; it will remove plugins from the active_plugins array rather than add them.
  • The plugin should be a standalone solution; not dependent on other plugins or logic in the theme.
@bobbingwide
Copy link
Owner Author

bobbingwide commented Oct 24, 2021

CSV file format

In the oik-loader plugin the CSV file has a format of

URL,ID,plugins 1,plugin 2,etc

where
URL is the URL eg /cwiccer/ or /cwiccer/blog/
ID is the post ID of the particular URL
when there isn't a post associated with the URL the value is not set.
plugin 1,plugin 2,etc is the list of plugins

oik-unloader will use the same format file.

  • The file will be called oik-unloader.blog.csv where blog is the blog ID
  • This is normally 1 for a single site installation.
  • For a WordPress Multi Site network site it's an integer.
  • Note: We won't cater for networks of Multi Sites.
  • The file will be stored in the mu-plugins folder.
  • If the folder does not exist we'll have to create it when the first URL is added
  • There should be options to Add, Edit or Delete entries for an URL

The first version of oik-unloader will assume we're using permalinks.
We probably don't need to be able to edit posts using the post ID.
The solution will have to cater for finding the post ID for the URL and vice-versa.

When any change is applied the update will be performed in memory then the CSV file written out and reloaded.

@bobbingwide
Copy link
Owner Author

OK, so that's v0.0.0 zipped.

Now I need to:

  • test it in a number of different environments ( local development and live sites? )
  • measure the improvements in server side processing, using slog and oik-bwtrace
  • measure the improvements to front end performance using Lighthouse

@bobbingwide
Copy link
Owner Author

test it in a number of different environments

I had to fix quite a few problems in s.b/hm for the initial install where mu-plugins didn't exist and oik-unloader.1.csv didn't exist or was empty.

Tested on sb/hm deactivating Yoast SEO

I tested with and without SEO and also with oik-bwtrace turned on and off.
The results show that the system is faster when tracing is turned off
and even faster when Yoast SEO is deactivated.

image

@bobbingwide
Copy link
Owner Author

measure the improvements to front end performance using Lighthouse

It's a bit tricky to test the front end performance improvements when they're already 100 for both Mobile and Desktop
image

@bobbingwide
Copy link
Owner Author

bobbingwide commented Oct 25, 2021

In s.b/hm I tried a rather drastic test. I selected just about every plugin to be deactivated. This caused the page to appear as a WSOD. Reducing the number of plugins to be deactivated, I did get some results but I also got Warnings which coincided with invalid HTML generated.

Warning: Undefined array key 0 in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\block-supports\elements.php on line 47

Warning: Trying to access array offset on value of type null in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\block-supports\elements.php on line 47

Warning: Undefined array key 0 in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\block-supports\elements.php on line 59

Warning: Trying to access array offset on value of type null in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\lib\block-supports\elements.php on line 59

I've had this problem before when developing Written.

Workaround

Don't deactivate sb-post-edit-block.

@bobbingwide
Copy link
Owner Author

There's another problem. The multi select list is not particularly user friendly. Consider changing it to a list of checkboxes.

@bobbingwide
Copy link
Owner Author

oik-unloader v0.0.1 is now available. I'm going to test it on a number of sites and collate the results.

  • Run Lighthouse before
  • Run Lighthouse after installing oik-unloader
  • Run Lighthouse after deactivating plugins
  • I'll also run slog for each stage

@bobbingwide
Copy link
Owner Author

I'm going to test it on a number of sites and collate the results.

Results reported in oik-unloader: WordPress performance improvement plugin

oik-unloader v0.0.1 now available from oik-plugins sites:

User docs to be copied/cobbled from the post in herbmiller.me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant