Page MenuHomeSoftware Heritage

Investigate why the WordPress website is so slow to load pages
Closed, MigratedEdits Locked

Description

Our WordPress website is terribly slow to load pages (several seconds which is not great).
This can be observed on our Gandi instance but also on the local version I use for development.

This seems related to the PHP code executed server side.

In order to identify the bottleneck, a profiling of that code is required.

This should be feasible by generating a flame graph using the PHP Xdebug extension

Revisions and Commits

Event Timeline

anlambert triaged this task as Normal priority.Mar 31 2021, 11:20 AM
anlambert created this task.

Below are the flame graphs I managed to produce, first one corresponds to the home page of the website while the second corresponds to the Collect and Curate Legacy Code page.

It seems the bottleneck is some Layers theme code related to the dynamic sidebar used in the WordPress customizer.

From my point of view, this code should not be executed as we did not request to customize the pages.

I need to dig further on this.

My first analysis was biased by the flame graphs rendering, dynamic sidebar code is not the bottleneck here.

After discarding some fast execution branches by hacking in our PHP code, I managed to find the real bottleneck: the recently added Content Control plugin.

Looking at its code, it will filter widgets according to user roles each time a page is loaded, but it uses the full list of widgets
instead of only those embedded in the page. So as we have a LOT of widgets, this is pretty damn slow.

Deactivating the plugin effectively remove the slowdown when loading a page.

I need to do more analysis on the code but I should manage to find a workaround.

This is the best workaround I found so far, adding that piece of code at the end of our functions.php file.

// deactivate costly content control widget filtering (due to the numerous
// layers theme widgets created for swh site) on pages where we do not need it
$page_url = add_query_arg($wp->query_vars, home_url());
if (!strpos($page_url, 'ambassador-material')) {
  remove_action('sidebars_widgets', array('JP\CC\Site\Widgets', 'exclude_widgets'));
}

The filtering of widgets based on user roles is only needed for the Ambassador material page so this removes
such filtering on other pages.

anlambert added a commit: Restricted Diffusion Commit.Mar 31 2021, 7:49 PM

Fix is now deployed to production, pages loading time is now much faster (< 1s), closing this as resolved.