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

Performance Optimizations (part 2) #3172

Closed
4 tasks
bfintal opened this issue Apr 26, 2024 · 0 comments · Fixed by #3178
Closed
4 tasks

Performance Optimizations (part 2) #3172

bfintal opened this issue Apr 26, 2024 · 0 comments · Fixed by #3178
Assignees

Comments

@bfintal
Copy link
Contributor

bfintal commented Apr 26, 2024

Optimizations To Do:

Remove stackable_add_custom_orderby_params and stackable_add_custom_orderby

  • Done

These 2 filters are only here because we need to add random and menu order sorting options in the Stackable Posts block. However, it's slowing down WP because every time posts are used, the filters are also applied.

I suggest removing these 2 filters and creating our own "Post getter" rest api endpoint for the Stackable Posts block. If we create our own, then there will be no need to add filters and extend the post rest api with our own filters. If this is done, this can also fix the next entry below.

Here's a screenshot of a profiler session when saving a post

Image


Create a new page and add a tabs block with 5 tabs containing the following: pricing table with icon list of different icons. Profile the editor URL, you'll see that the code for get_excerpt_by_post_id is slow:

  • Done

image

Upon further investigation, it appears that in src/block/posts/index.php we are registering a bunch of new rest fields for posts in register_rest_fields. By registering new rest fields, ALL rest API calls for posts will now compute for these new fields (even when the editor just loads).

We need to change this behavior because the added data are only needed during the generation of the Stackable post block's content in the editor here:

return generateRenderPostItem( attributes, { isHovered: props.isHovered } )

Because the field is added in register_rest_fields, now whenever posts are queried, it also calls our functions. We need to change the following:

  1. remove the added fields from register_rest_fields or only add them when generating Stackable post block content
  2. or, the implementation of generateRenderPostItem and usePostsQuery to query a new rest API endpoint that grabs the necessary post data for displaying in the post block content.

Create a new page and add a posts block. Profile the editor URL, you'll see that the posts block code is quite slow:

  • Done

image


Change block registration method. To check, profile the Settings > General page. Do not do this for now

  • Done

Our blocks are registered using the function register_block_type_from_metadata it's reading the block.json files and registering it using the properties found in those files. I think this might be slow.

image

We can try placing all the relevant data from block.json files into a PHP object (maybe with a script that auto-compiles things if we prove this to be a good optimization strategy) then use register_block_type to register the blocks instead. This way we do not need to do any file read/writes and might bring down the execution time.

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

Successfully merging a pull request may close this issue.

2 participants