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

Call variation through callback so it's only loaded when needed - in support of trac 59969 #56952

Merged

Conversation

kt-12
Copy link
Member

@kt-12 kt-12 commented Dec 11, 2023

What?

This PR will help build variations only when we need to load them instead of during resignation at the init hook.

Core PR with detailed performance analysis ->
WordPress/wordpress-develop#5718

Why?

Currently, we run a performance-heavy build variation function for some of the blocks in init hook, which causes it to load even on the frontend where it is not needed.

How?

In this PR we register only the callback during block registration and build the variation only when they are needed.

Note: This PR provides around ~9% improvement to the frontend load time but it has no improvement for the editor site. However, we have found some way by which similar performance benefits could be obtained at the editor side - WordPress/wordpress-develop#5718 (comment)

Testing Instructions

Test it for the TT4 theme.

  1. Open the editor.
  2. Open the browser console and type wp.blocks.getBlockType('core/post-terms')
  3. Ensure that the block object returned has variation. Do the same for core/navigation-link, core/template-part

Testing Instructions for Keyboard

Screenshots or screencast

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Dec 11, 2023
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @kt-12! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@joemcgill joemcgill added the [Type] Performance Related to performance efforts label Dec 11, 2023
Copy link
Member

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpic, otherwise looks good.

lib/compat/wordpress-6.4/block-hooks.php Outdated Show resolved Hide resolved
@kt-12 kt-12 requested a review from spacedmonkey January 15, 2024 11:41
Copy link
Member

@spacedmonkey spacedmonkey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @kt-12 .

I can merge this once the automated tests pass.

@spacedmonkey spacedmonkey added the Needs PHP backport Needs PHP backport to Core label Jan 15, 2024
@spacedmonkey spacedmonkey merged commit 2c247e2 into WordPress:trunk Jan 16, 2024
54 of 55 checks passed
@github-actions github-actions bot added this to the Gutenberg 17.6 milestone Jan 16, 2024
@Mamaduka
Copy link
Member

I believe this PR won't need a manual PHP backport.

@tellthemachines
Copy link
Contributor

@Mamaduka doesn't the change in lib/compat/wordpress-6.5/blocks.php need to be added to core?

@Mamaduka
Copy link
Member

@tellthemachines, no, it's a shim for a new property to work with older WP versions. It can be removed after the required version is 6.5.

@getdave
Copy link
Contributor

getdave commented Jan 22, 2024

✅ I updated the PHP Sync Tracking Issue to note this PR does not require a backport.

@@ -115,6 +115,8 @@
<element value="apply_block_core_search_border_style"/>
<element value="apply_block_core_search_border_styles"/>
<element value="build_dropdown_script_block_core_categories"/>
<element value="build_navigation_link_block_variations"/>
Copy link
Contributor

@anton-vlasenko anton-vlasenko Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kt-12, I appreciate your efforts with the ignore list. However, these functions weren't part of the initial setup and don't pose any backward compatibility issues if we stick to the naming conventions enforced by the sniff.
For example, they could be renamed to block_core_template_part_build_area_variations() and block_core_post_terms_build_variations() respectively. Could you please rename them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the follow-up #58538.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names I suggested for these functions were not exactly correct, but the idea was to adhere to the coding standard. Thanks for fixing it, @Mamaduka.
I have approved your PR.

@youknowriad youknowriad removed the Needs PHP backport Needs PHP backport to Core label Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants