#59178 closed enhancement (fixed)
Performance optimization of wp_get_block_css_selector()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.4 | Priority: | normal |
Severity: | normal | Version: | 6.3 |
Component: | Editor | Keywords: | needs-patch has-screenshots good-first-bug |
Focuses: | performance | Cc: |
Description
On the TT3 home page, a single post with content (including an image and text) is causing calls to the wp_get_block_css_selector
function during testing. This function call occurs 567 times, which is significantly impacting performance. A deeper analysis reveals that the array_merge
function is being called 372 times within the wp_get_block_css_selector
function, leading to unnecessary overhead.
According to measurements taken using the XHProf tool, these activities are consuming approximately 2% of the total load time for the page. Addressing this issue has the potential to not only enhance performance but also contribute to improved memory management, as demonstrated in the attached screenshot.
Additional props to @joemcgill for helping to identify the bug!
Attachments (1)
Change History (7)
This ticket was mentioned in PR #5072 on WordPress/wordpress-develop by @daxelrod.
19 months ago
#1
- Keywords has-patch added; needs-patch removed
@daxelrod commented on PR #5072:
19 months ago
#2
Unless there is a noticeable performance benefit, I'm not sure this optimization is worth it. This is my attempt to remove array_merge() as simply as possible, but a larger refactor could be more readable and performant.
#3
@
19 months ago
- Keywords needs-patch added; has-patch removed
I was looking into this and wondering what was the original idea of using array_merge()
to add a single element to the array? This could help decide the best approach to improve the performance of the function.
#4
@
19 months ago
- Owner set to davidbaumwald
- Resolution set to fixed
- Status changed from new to closed
In 56457:
#5
@
19 months ago
- Milestone changed from Awaiting Review to 6.4
Thanks @davidbaumwald for committing it.
Moving this ticket to 6.4
milestone.
@mukesh27 commented on PR #5072:
19 months ago
#6
Committed in https://core.trac.wordpress.org/changeset/56457
Performance optimization of wp_get_block_css_selector() by removing array_merge() with an inline array. The current() function only works because must only have one element to within the block.