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

Improve performance of compute_style_properties method. #62522

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

spacedmonkey
Copy link
Member

@spacedmonkey spacedmonkey commented Jun 12, 2024

Improve logic in compute_style_properties to improve performance. This commit fixes a number of performance issues including.

  • Expensive repeated call to str_starts_with.
  • Return easy if not array.
  • Repeated call to strlen.
  • Move call to get_property_value where it is needed.
  • Move call to implode to after empty check.

What?

Why?

Before

Screenshot 2024-06-12 at 22 52 46

After

Screenshot 2024-06-12 at 22 55 05

How?

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Improve logic in compute_style_properties to improve performance. This commit fixes a number of performance issues including.

- Expensive repeated call to `str_starts_with`.
- Return easy if not array.
- Repeated call to `strlen`.
- Move call to `get_property_value` where it is needed.
- Move call to implode to after empty check.
Copy link

github-actions bot commented Jun 12, 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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @jonnynews.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Unlinked contributors: jonnynews.

Co-authored-by: spacedmonkey <spacedmonkey@git.wordpress.org>
Co-authored-by: joemcgill <joemcgill@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: ellatrix <ellatrix@git.wordpress.org>

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

Copy link

github-actions bot commented Jun 12, 2024

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core GitHub repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/class-wp-theme-json-gutenberg.php

@spacedmonkey spacedmonkey added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Jun 12, 2024
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 like a good refactor to me. Left a couple of comments inline.

lib/class-wp-theme-json-gutenberg.php Outdated Show resolved Hide resolved
lib/class-wp-theme-json-gutenberg.php Show resolved Hide resolved
Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com>
Copy link

Flaky tests detected in eca89a5.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9512834878
📝 Reported issues:

@ellatrix
Copy link
Member

The Backport to WP Beta/RC label can be removed here since this will need to be backported manually, not through packages. Once a backport PR is made, add a changelog entry for 6.6 and we'll keep track of it that way.

@spacedmonkey
Copy link
Member Author

The Backport to WP Beta/RC label can be removed here since this will need to be backported manually, not through packages. Once a backport PR is made, add a changelog entry for 6.6 and we'll keep track of it that way.

That is not how that works. All PRs that need to be manaully ported over, have that label assigned and are added the backport issue. Has this been changed? Where is that documented?

@ellatrix
Copy link
Member

Sure, it's fine to leave the label. Most important is that there's a core PR.

@spacedmonkey
Copy link
Member Author

Core PR WordPress/wordpress-develop#6707. Will update and commit once this PR is merged.

@ellatrix ellatrix added the [Type] Performance Related to performance efforts label Jun 20, 2024
@spacedmonkey spacedmonkey merged commit 3ff9331 into trunk Jun 24, 2024
67 of 71 checks passed
@spacedmonkey spacedmonkey deleted the fix/improve-perfromance-theme-json branch June 24, 2024 16:53
@github-actions github-actions bot added this to the Gutenberg 18.7 milestone Jun 24, 2024
ellatrix pushed a commit that referenced this pull request Jun 25, 2024
* Improve performance of `compute_style_properties` method.

Improve logic in compute_style_properties to improve performance. This commit fixes a number of performance issues including.

- Expensive repeated call to `str_starts_with`.
- Return easy if not array.
- Repeated call to `strlen`.
- Move call to `get_property_value` where it is needed.
- Move call to implode to after empty check.

* Fix lint.

* Apply suggestions from code review

Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com>

---------

Co-authored-by: Jonny Harris <jonathan.harris@news.co.uk>
Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com>
@ellatrix
Copy link
Member

I just cherry-picked this PR to the wp/6.6-rc-1 branch to get it included in the next release: 1116c38

@ellatrix ellatrix added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Jun 25, 2024
ellatrix pushed a commit that referenced this pull request Jun 25, 2024
* Improve performance of `compute_style_properties` method.

Improve logic in compute_style_properties to improve performance. This commit fixes a number of performance issues including.

- Expensive repeated call to `str_starts_with`.
- Return easy if not array.
- Repeated call to `strlen`.
- Move call to `get_property_value` where it is needed.
- Move call to implode to after empty check.

* Fix lint.

* Apply suggestions from code review

Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com>

---------

Co-authored-by: Jonny Harris <jonathan.harris@news.co.uk>
Co-authored-by: Joe McGill <801097+joemcgill@users.noreply.github.com>
@ellatrix
Copy link
Member

Why did you merge this with failing tests? A backport changelog entry should have been added for this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants