Make WordPress Core

Opened 2 years ago

Last modified 9 months ago

#59301 assigned enhancement

Incorporate script loading strategies in WP Admin to improve performance where applicable

Reported by: westonruter's profile westonruter Owned by: adamsilverstein's profile adamsilverstein
Milestone: Future Release Priority: normal
Severity: normal Version: 6.3
Component: Administration Keywords: needs-patch
Focuses: javascript, performance Cc:

Description

As of #12009 the script loader now has the ability for scripts to be printed with async or defer. This is being used on the frontend now for block view scripts (#59115), the comment-reply script (#58870), and the wp-embed script (#58931). Nevertheless, these new script loading strategies are not currently being used in the admin. There may be opportunities to improve performance by doing so.

Typically only jquery-core, jquery-migrate, and utils (less frequently moxiejs and plupload, and even less frequently wp-polyfill-inert, regenerator-runtime, wp-polyfill, wp-hooks, zxcvbn-async, wp-codemirror, and underscore) are loaded in the head in the admin; furthermore, these scripts are concatenated together via load-scripts.php. For backwards-compatibility, these scripts might not be able to be delayed or moved to the footer. In other cases, there may be existing footer scripts that could be moved to the head and made to load with defer: this would ensure that they start loading sooner so that they can execute as soon as the document finishes loading. Other scripts could potentially be lazy-loaded only when needed (e.g. zxcvbn).

Note that the block/site editor screens will benefit the most from block lazy loading.

Change History (10)

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


2 years ago

#2 follow-up: @tabrisrp
2 years ago

Is there already some steps that were discussed for this?

#3 in reply to: ↑ 2 @westonruter
2 years ago

Replying to tabrisrp:

Is there already some steps that were discussed for this?

Steps in what way? Like specific scenarios which were identified in the admin where async/defer scripts would improve performance? No.

#4 @flixos90
16 months ago

  • Keywords good-first-bug added

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


13 months ago

#6 @adamsilverstein
13 months ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

#7 @SirLouen
9 months ago

  • Keywords needs-patch added

Amazed to see the full Google crew on the same ticket. But I'm not sure if this is a good-first-bug candidate (just wondering why no one put a foot in almost 2 years, this is an interesting ticket that requires extensive analysis and somewhat complex to identify dependencies to best select async instead of defer and preserve loading order without conflicts).

In fact, I would say that this should be more a blessed task than a singular enhancement because many interactions should be done to get to a quality result in this same ticket (and for different admin areas, dashboard, post editor,...)

This said, some ideas for anyone willing to start working on this:

Reproduction and Working Steps

  1. For any user willing to take this (or a part of this), my recommendation: You don't need to (and you should not) submit the whole patch with full optimizations. With just 1, 2 or 3 proven optimizations, it will be enough to submit a patch that can be committed individually. The more optimizations in one patch, the more is going to take to be evaluated, hence, committed.
  1. Start adding just one defer to one of the last loading scripts (check script loading order in and test performance improvement). Keep doing this in backward order until you have deferred in order all the scripts without breaking the admin area.
  1. Then try to figure out, which scripts don't have any dependencies from the deferred list and try to async them instead. Keep checking performance every change.
  1. For performance checking, personally I like to purposely hinder the browser to get big consistent numbers in seconds rather than fast decimals that tend to have too much variation. For example, hindering CPU to 4x slowdown and working on Slow 4G is sufficient in most cases as you will quickly get anything over 10 seconds LCP where you will clearly see the effects of this performance tweaks.
  1. Testing is equally complicated; hence, ideally, once should start from the scripts at the bottom of the waterfall. I just took one random script that I've checked that it's an end-script without dependencies, but it's safer to start with the last ones that should not have dependencies for obvious reasons, in this case, some script like autocomplete.js

For example, with these parameters, deferring dashboard.js as the patch I've submitted, we can see that it's no longer render blocking, but it is not necessarily going to improve performance much (or at all), at least in this case, so maybe we should consider if leaving it or just ignoring.

Before:
https://i.imgur.com/SVB1WUh.png

After:
https://i.imgur.com/DPrqphV.png

Finally, I'm wondering to which extent, old browsers should be respected in this regard and use strategy => defer instead of in_footer => true, which is much orderly. Personally, I don't know which policy is taking WP in regard of this topic.

PS: Located this little dependency issue while testing #63432, so this also seems a good debugging exercise.

Last edited 9 months ago by SirLouen (previous) (diff)

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


9 months ago
#8

  • Keywords has-patch added; needs-patch removed

This is a proof of concept to move the needle a little on ticket 59301.

Trac ticket: https://core.trac.wordpress.org/ticket/59301

#9 @SirLouen
9 months ago

  • Keywords needs-patch added; has-patch removed

#10 @johnbillion
9 months ago

  • Keywords good-first-bug removed
Note: See TracTickets for help on using tickets.