[wp-trac] [WordPress Trac] #59544: Performance: Skip iteration in block supports elements when not necessary.
WordPress Trac
noreply at wordpress.org
Wed Oct 4 22:51:50 UTC 2023
#59544: Performance: Skip iteration in block supports elements when not necessary.
-------------------------+-----------------------------
Reporter: dmsnell | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: trunk
Severity: normal | Keywords: has-patch
Focuses: performance |
-------------------------+-----------------------------
**Quick notes**
- This is intended to address performance regressions in the 6.4 beta
release in combination with the front page of `twentytwentyfour`. It's
half a bug-fix and half an enhancement.
- It needs a backport into Gutenberg because it comes over in a Gutenberg
package. I am going to ensure this happens as it needs to, but given the
relation to the release, I would prefer we fast-track this into Core first
if it finds favorable review and confirmed impact.
**Description**
Previously there have been three ways in which the block supports elements
code has been performing computation it doesn't need to.
- It checks for every possible style attribute on a block even if there
are no possible style attributes available on the block.
- Once it determines that it needs to add a special class to a block it
continues scanning through the rest of the attributes.
- It constructs dot-separated literal key paths for the attributes and
immediately and repeatedly calls `explode()` on them to create an array at
runtime.
The combination of these three factors leads to an outsized impact of this
function on the runtime and memory pressure for what it's doing. This
patch removes all three of these inefficiencies:
- If no elements style attributes exist on the block it immediately
returns and skips all further processing.
- It stops scanning block attributes once a single one is found that
imposes the requirement for the extra class name.
- It constructs array literals for the key path instead of strings. This
removes the need to artificially join and explode the keys at runtime.
There should be no functional or visual changes in this patch, but it
should reduce the overall runtime of page renders and require less memory
while rendering. The impact will be proportional to the number of blocks
rendered on a page.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59544>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list