#62317 closed enhancement (fixed)
Optimize "WP_Style_Engine::parse_block_styles()" by reducing unnecessary "array_merge" calls
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.8 | Priority: | normal |
| Severity: | normal | Version: | 6.1 |
| Component: | Editor | Keywords: | has-patch commit |
| Focuses: | performance | Cc: |
Description
While benchmarking WordPress 6.7, a significant number of array_merge calls were observed, particularly within the WP_Style_Engine::parse_block_styles() function in TT4 theme. The repeated, unnecessary calls to array_merge impacted performance
This update optimizes WP_Style_Engine::parse_block_styles() by conditionally merging classnames and CSS declarations only when they are not empty. This removes several unwanted calls to array_merge and helps improve performance, especially for themes with extensive styles.
Change History (10)
This ticket was mentioned in PR #7670 on WordPress/wordpress-develop by @mukesh27.
18 months ago
#1
- Keywords has-patch added; needs-patch removed
@mukesh27 commented on PR #7670:
18 months ago
#2
@ramonopoly commented on PR #7670:
18 months ago
#3
Thanks for testing!
One very minor question on the code here, is it worth type checking the return values from get_css_declarations etc?
From memory, that can in turn call other functions from the style declaration. So I was wondering if we could benefit from future proofing this a little
So is_array or something? The value functions are all internal for now, and they all return array() consistently.
But if we ever open that up for extension, it would be a good idea.
@aaronrobertshaw commented on PR #7670:
18 months ago
#4
So is_array or something? The value functions are all internal for now, and they all return array() consistently.
Yeah, that's what I meant.
In addition to the scenario where the style engine was made external, I was thinking for people less familiar with the style engine that came to add style declarations but missed that array return value requirement.
No need to address it now. I was mostly just thinking out loud.
@mukesh27 commented on PR #7670:
18 months ago
#5
Thanks for the review.
One very minor question on the code here, is it worth type checking the return values from get_css_declarations etc?
@aaronrobertshaw @ramonjd I believe we should open a Trac ticket to facilitate further discussion, allowing us to implement this in the future if needed.
@joemcgill @felixarntz, could you please take a look when you have a moment? This way, we can proceed with committing it for 6.8.
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
17 months ago
#7
@
17 months ago
- Keywords commit added
The PR got enough approval and GB backport PR already merged.
Trac ticket: https://core.trac.wordpress.org/ticket/62317