-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Optimize preload paths for post and site editors #39256
Conversation
Size Change: +65 B (0%) Total Size: 1.16 MB
ℹ️ View Unchanged
|
9815174
to
1e462d6
Compare
lib/init.php
Outdated
* @param array $preload_paths Preload paths to be filtered. | ||
* @return array | ||
*/ | ||
function optimize_preload_paths( $preload_paths ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function filters patches the preload_paths
list created in Core when loading the block editor page.
When a Core patch with these changes is merged, the filter becomes a noop. The Core list and the Gutenberg plugin will always be out of sync, so this filter will patch the list according to latest Gutenberg's requirements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should move this change to lib/wordpress-6.0/edit-form-blocks.php
, that way it's easier for us to know when to remove that code from the plugin (minimum supported version) and how to backport it to Core (same file name).
We should probably do the same for the file above but I guess since it was not done before for the remaining parts of that file, it's fine to keep your changes there for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, moved the edit-form-blocks
bits to lib/compat
.
About the edit-site-page.php
modifications: there's not a direct counterpart to that file in Core. The Gutenberg plugins ships a completely standalone page for Full Site Editing, one that's not interacting or integrated with the one in Core at all. Its URL is /wp-admin/themes.php?page=gutenberg-edit-site
, while the Core equivalent is /wp-admin/site-editor.php
. The Gutenberg plugin intercepts all the links and replaces them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll drop using a custom page for the Site Editor once the Gutenberg plugin requires WP 5.9 or later.
I wonder if we can add a "payload size" metric to our performance tests to keep track of this over time. |
Are the preload paths in Core (i.e. with the Gutenberg Plugin disabled) also not correct? Wondering if we need to update the paths there. |
I just discovered that this was a recent intentional change in #37685. That PR was supposed to also change the preloads but it didn't. This PR fixes that. |
1bc6bda
to
e96127c
Compare
Yes, I just created a companion patch here: https://core.trac.wordpress.org/ticket/55337. It applies the changes that the filter in this PR would do. Except changing the |
e96127c
to
9a94170
Compare
Nice find @jsnajdr! ✨ Leaving a note here that it does look like the change here shows an improvement in several site-editor stats: https://github.com/WordPress/gutenberg/runs/5463257206
There doesn't appear to be any effect on the post-editor, but I assume this needs WordPress/wordpress-develop#2387 to be applied. Note that it's possible to run performance tests locally with:
And if folks need to debug the performance test scripting, it's possible with:
|
The Core patch doesn't need to be there -- it merely directly changes the paths in The |
Running the
|
I triggered another run, but the second run now shows improvements for the post-editor and not much change in the site-editor. We may need to revisit how we're measuring this. We could be seeing some variance from the fact that the post editor has a much smaller skeleton size. Locally (with npm run build) I'm seeing 82KB (this branch) vs 95KB (trunk), while the site editor has a skeleton size of around 1.1MB (depending on your template content). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work here @jsnajdr! Changes here make sense to me and I didn't see any regressions while smoke testing. It may be worthwhile to get another +1
This looks more like a confusion between compressed and uncompressed size of the response. In my bare bones
|
Thank you @jsnajdr, cool to see the optimization! |
@jsnajdr Actually it's dependent on site content. My template uses a query loop with some large test posts and this bloats the initial document size. Try publishing large posts similar to the ones used in the performance tests. Here's a quick video of just one published post making a difference in the document size. There's a much more notable effect when one has a number of large test posts. 264KB vs 78KB when we trash it. CleanShot.2022-03-10.at.09.26.44.mp4 |
This patch optimizes preload paths in post and site editors so that they match the real requests: - Remove the `/` preload as the payload is very big and the response is not needed on any critical path. - Modify the preloaded path for `/wp/v2/taxonomies` so that it corresponds to what `loadTaxonomyEntities` requests. After Gutenberg PR 37685 was merged to core, these preloads need to be modified to use `context=view` instead of `context=edit`. - Modify the `/wp/v2/users/me path` so that it matches the real request (no query params). - Add a preload of `/wp/v2/settings` because it is requested on critical path (editor boot). Site editor already preloads this, the changeset is only adding it to the post editor. This is related to Gutenberg PR 39256 which introduces compatibility code to modify the preload paths with a filter, when the Gutenberg plugin is active. See WordPress/gutenberg#39256. Props jsnajdr, noisysocks. Fixes #55337. git-svn-id: https://develop.svn.wordpress.org/trunk@52995 602fd350-edb4-49c9-b593-d223f7449a82
This patch optimizes preload paths in post and site editors so that they match the real requests: - Remove the `/` preload as the payload is very big and the response is not needed on any critical path. - Modify the preloaded path for `/wp/v2/taxonomies` so that it corresponds to what `loadTaxonomyEntities` requests. After Gutenberg PR 37685 was merged to core, these preloads need to be modified to use `context=view` instead of `context=edit`. - Modify the `/wp/v2/users/me path` so that it matches the real request (no query params). - Add a preload of `/wp/v2/settings` because it is requested on critical path (editor boot). Site editor already preloads this, the changeset is only adding it to the post editor. This is related to Gutenberg PR 39256 which introduces compatibility code to modify the preload paths with a filter, when the Gutenberg plugin is active. See WordPress/gutenberg#39256. Props jsnajdr, noisysocks. Fixes #55337. Built from https://develop.svn.wordpress.org/trunk@52995 git-svn-id: http://core.svn.wordpress.org/trunk@52584 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This patch optimizes preload paths in post and site editors so that they match the real requests: - Remove the `/` preload as the payload is very big and the response is not needed on any critical path. - Modify the preloaded path for `/wp/v2/taxonomies` so that it corresponds to what `loadTaxonomyEntities` requests. After Gutenberg PR 37685 was merged to core, these preloads need to be modified to use `context=view` instead of `context=edit`. - Modify the `/wp/v2/users/me path` so that it matches the real request (no query params). - Add a preload of `/wp/v2/settings` because it is requested on critical path (editor boot). Site editor already preloads this, the changeset is only adding it to the post editor. This is related to Gutenberg PR 39256 which introduces compatibility code to modify the preload paths with a filter, when the Gutenberg plugin is active. See WordPress/gutenberg#39256. Props jsnajdr, noisysocks. Fixes #55337. Built from https://develop.svn.wordpress.org/trunk@52995 git-svn-id: https://core.svn.wordpress.org/trunk@52584 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This patch optimizes preload paths in post and site editors so that they match the real requests: - Remove the `/` preload as the payload is very big and the response is not needed on any critical path. - Modify the preloaded path for `/wp/v2/taxonomies` so that it corresponds to what `loadTaxonomyEntities` requests. After Gutenberg PR 37685 was merged to core, these preloads need to be modified to use `context=view` instead of `context=edit`. - Modify the `/wp/v2/users/me` path so that it matches the real request (no query params). - Add a preload of `/wp/v2/settings` because it is requested on critical path (editor boot). Site editor already preloads this, the changeset is only adding it to the post editor. This is related to Gutenberg PR 39256 which introduces compatibility code to modify the preload paths with a filter, when the Gutenberg plugin is active. See WordPress/gutenberg#39256. Props jsnajdr, noisysocks. Merges [52995] to the 5.9 branch. git-svn-id: https://develop.svn.wordpress.org/branches/5.9@53005 602fd350-edb4-49c9-b593-d223f7449a82
This patch optimizes preload paths in post and site editors so that they match the real requests: - Remove the `/` preload as the payload is very big and the response is not needed on any critical path. - Modify the preloaded path for `/wp/v2/taxonomies` so that it corresponds to what `loadTaxonomyEntities` requests. After Gutenberg PR 37685 was merged to core, these preloads need to be modified to use `context=view` instead of `context=edit`. - Modify the `/wp/v2/users/me` path so that it matches the real request (no query params). - Add a preload of `/wp/v2/settings` because it is requested on critical path (editor boot). Site editor already preloads this, the changeset is only adding it to the post editor. This is related to Gutenberg PR 39256 which introduces compatibility code to modify the preload paths with a filter, when the Gutenberg plugin is active. See WordPress/gutenberg#39256. Props jsnajdr, noisysocks. Merges [52995] to the 5.9 branch. Built from https://develop.svn.wordpress.org/branches/5.9@53005 git-svn-id: http://core.svn.wordpress.org/branches/5.9@52594 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This patch optimizes preload paths in post and site editors so that they match the real requests: - Remove the `/` preload as the payload is very big and the response is not needed on any critical path. - Modify the preloaded path for `/wp/v2/taxonomies` so that it corresponds to what `loadTaxonomyEntities` requests. After Gutenberg PR 37685 was merged to core, these preloads need to be modified to use `context=view` instead of `context=edit`. - Modify the `/wp/v2/users/me` path so that it matches the real request (no query params). - Add a preload of `/wp/v2/settings` because it is requested on critical path (editor boot). Site editor already preloads this, the changeset is only adding it to the post editor. This is related to Gutenberg PR 39256 which introduces compatibility code to modify the preload paths with a filter, when the Gutenberg plugin is active. See WordPress/gutenberg#39256. Props jsnajdr, noisysocks. Merges [52995] to the 5.9 branch. Built from https://develop.svn.wordpress.org/branches/5.9@53005 git-svn-id: https://core.svn.wordpress.org/branches/5.9@52594 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This patch optimizes preload paths in post and site editors so that they match the real requests: - Remove the `/` preload as the payload is very big and the response is not needed on any critical path. - Modify the preloaded path for `/wp/v2/taxonomies` so that it corresponds to what `loadTaxonomyEntities` requests. After Gutenberg PR 37685 was merged to core, these preloads need to be modified to use `context=view` instead of `context=edit`. - Modify the `/wp/v2/users/me` path so that it matches the real request (no query params). - Add a preload of `/wp/v2/settings` because it is requested on critical path (editor boot). Site editor already preloads this, the changeset is only adding it to the post editor. This is related to Gutenberg PR 39256 which introduces compatibility code to modify the preload paths with a filter, when the Gutenberg plugin is active. See WordPress/gutenberg#39256. Props jsnajdr, noisysocks. Merges [52995] to the 5.9 branch. Built from https://develop.svn.wordpress.org/branches/5.9@53005
This patch optimizes preload paths in post and site editors so that they match the real requests: - Remove the `/` preload as the payload is very big and the response is not needed on any critical path. - Modify the preloaded path for `/wp/v2/taxonomies` so that it corresponds to what `loadTaxonomyEntities` requests. After Gutenberg PR 37685 was merged to core, these preloads need to be modified to use `context=view` instead of `context=edit`. - Modify the `/wp/v2/users/me` path so that it matches the real request (no query params). - Add a preload of `/wp/v2/settings` because it is requested on critical path (editor boot). Site editor already preloads this, the changeset is only adding it to the post editor. This is related to Gutenberg PR 39256 which introduces compatibility code to modify the preload paths with a filter, when the Gutenberg plugin is active. See WordPress/gutenberg#39256. Props jsnajdr, noisysocks. Merges [52995] to the 5.9 branch. Built from https://develop.svn.wordpress.org/branches/5.9@53005 git-svn-id: http://core.svn.wordpress.org/branches/5.9@52594 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This PR optimizes the preloaded data for REST endpoints. Some preloaded data are removed, some endpoints are modified, some are added.
Removing the
/
preload. One of the endpoints we preload is/
, where we use properties likesite_icon_url
orhome
. The response, however, also contains a hugeroutes
field, bloating the initial HTML response. Before we can filter them out with a_fields
query param, some Core patches will need to be merged first and that will take time.In this PR I'm simply removing the preload. It's not needed for anything critical and the editor is perfectly functional even without the data. The data are used, for example, to display the site logo in place of the WP logos here (the fullscreen-close and pre-publish panels):
That can certainly wait and doesn't need to block the editor initialization.
Fixing preloads for
postType
andtaxonomies
entities. There are functions that load entity data of certain types (postType
andtaxonomies
), required to resolve any selector for these entities. They call the endpoints withcontext=view
, but the preloads are forcontext=edit
and are not used. This PR fixes thecontext
params to match the real requests. An alternative way to fix this would be to change the actual requests tocontext=edit
. I'm not sure what's the difference and whether it matters. Up for discussion.Fixing preload for
users/me
. The preload is using a wrong URL:but we're fetching from just
The old URL hasn't been used for a very long time: it used to load user permissions for a particular post type, and was used to implement the
canUser
selector. But we've been usingOPTIONS
requests andAllow
response headers for that for a long time.Adding preload for
/settings
. The request is done on a critical path, in theuseBlockEditorSettings
hook, so all the settings had better be available as soon as possible.How to test:
Verify in the Network Devtool that none of these preloaded paths trigger a network request -- that would mean that the preloaded cached version was missed.
Verify that the initial HTML got significantly smaller as there are no longer data for the
/
endpoint.