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

Remove additional call to WP_Theme_JSON_Gutenberg::__construct #61262

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

kt-12
Copy link
Member

@kt-12 kt-12 commented Apr 30, 2024

What?

Introduce WP_Theme_JSON_Data_Gutenberg::get_theme_json() to avoid the cyclic call to WP_Theme_JSON_Gutenberg::__construct.

Trac ticket: Trac 61112

Why?

Doing similar changes in core, we got a consistent ~2.5% improvement by reducing 8 calls to the constructor reference core pr.

How?

WP_Theme_JSON_Data_Gutenberg internally has a theme_json private attribute which is an instance of WP_Theme_JSON_Gutenberg. At the moment we try to form the raw JSON data from the WP_Theme_JSON_Gutenberg object and then again from the Object from the raw JSON data, which leads to regression. In this PR we use the existing WP_Theme_JSON_Gutenberg object available to WP_Theme_JSON_Data_Gutenberg instead of the cyclic way.

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Copy link

github-actions bot commented Apr 30, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: kt-12 <thekt12@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: joemcgill <joemcgill@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@kt-12 kt-12 changed the title remove additional call to Remove additional call to WP_Theme_JSON_Gutenberg::__construct Apr 30, 2024
@joemcgill joemcgill added the [Type] Performance Related to performance efforts label Apr 30, 2024
Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

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

See related feedback in the original wordpress-develop PR WordPress/wordpress-develop#6271

$config = $theme_json->get_data();
return new WP_Theme_JSON_Gutenberg( $config, 'custom' );

return $theme_json->get_theme_json();
Copy link
Member

Choose a reason for hiding this comment

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

A bit below, there's another WP_Theme_JSON_Data_Gutenberg call but we cannot update it as we do on this one. That code is different than the core code and we need to consolidate both. That's a follow-up PR that shouldn't prevent this one from landing.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps we can absorb $config['isGlobalStylesUserThemeJSON'] = true; as part of WP_Theme_JSON_Data_Gutenberg. We may want to still check that's true before returning to be extra-safe (line 553) but we wouldn't need a second transformation.

Copy link
Member Author

Choose a reason for hiding this comment

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

@oandregal I observed it but presumed that GB and Core might be doing things differently here. I'll look at how to incorporate that in a different PR.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like the $config['isGlobalStylesUserThemeJSON'] modification was made as part of 2012a36 (#58409).

@ajlende is there a reason why this would still be necessary if we use the WP_Theme_JSON_Gutenberg object already present in the WP_Theme_JSON_Data_Gutenberg object?

Copy link
Member

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

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

This looks good to me. I think looking at the isGlobalStylesUserThemeJSON question can be resolved in a follow-up PR.

$config = $theme_json->get_data();
return new WP_Theme_JSON_Gutenberg( $config, 'custom' );

return $theme_json->get_theme_json();
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the $config['isGlobalStylesUserThemeJSON'] modification was made as part of 2012a36 (#58409).

@ajlende is there a reason why this would still be necessary if we use the WP_Theme_JSON_Gutenberg object already present in the WP_Theme_JSON_Data_Gutenberg object?

@joemcgill
Copy link
Member

@oandregal I don't have permissions to merge this PR but am planning to commit the related Core PR this week. Can you help us get this one shipped in a GB release as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants