Fix performance regression in the block-level custom CSS feature#11686
Fix performance regression in the block-level custom CSS feature#11686mukeshpanchal27 wants to merge 9 commits intoWordPress:trunkfrom
Conversation
Add early return for empty custom CSS class string
|
Based on @westonruter’s findings (https://gist.github.com/westonruter/5ae4155059d2135197976f324d00645c#file-spx-claude-analysis-md), it looks like this runs for every block. Since most blocks don’t have a custom class, we should return early so we don’t end up calling |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
I asked Claude Opus 4.7 to review this change with the SPX profile reports loaded as context: Looking at the PR's actual change vs. my profile data — it's a real micro-optimization but the gain is tiny in absolute terms. Here's the math: What the PR doesAdds an early What the profile said about this functionFrom my three runs:
The Realistic per-request savings
So on the order of 100µs per page request in the homepage case, more like 10–20µs on a small page. Well under 1% of the wp70 regression, and probably less than that in production (profiler overhead inflates per-call costs). VerdictIt's a legitimate, zero-risk fix — six added lines, no behavior change since The bigger lesson: the regression in this code path lives one level up.
The structural fix would be to not register the filter at all unless there's at least one block with custom CSS support enabled (which is rare — it's an opt-in feature). A check at Same pattern applies to Worth landing this PR as-is, but I'd encourage the contributor (or you) to also propose conditional filter registration as the larger follow-up. |
Add check for empty custom CSS before block support validation.
|
@westonruter Thanks for the report 😄 While we’re figuring out the best way to register the filter, I updated the PR with a change that avoids calling the Block Registry: a331593 |
Here's Claude's analysis with this addition: The new revision adds a second, more impactful optimization. Now there are two changes: Change 1 (unchanged):
|
|
I obtained the SPX report before and after.
Per Claude, that accounts for:
The 891 number is the smoking gun — it matches exactly the count of Just to put the magnitude in perspective: 0.48% fewer function dispatches per request. If average dispatch cost is ~1µs (reasonable order-of-magnitude on warm opcache), that's ~3.5ms of savings — and that's why call counts are a more sensitive instrument than wall time for changes this size. It's also why the wall-time delta is invisible: ~3.5ms of expected savings is right in the same ballpark as the ±2ms run-to-run drift in your 500-iteration medians. (Weston here) I ran Without the fix applied:
With the fix applied:
Claude's analysis of this data: Honest reading: the PR's measured wall-time impact is statistically zero at this scale. Both runs land at ~231ms
A 1.63ms median delta on a 230ms baseline is +0.7% — well within run-to-run drift between two separate 500-iteration runs. Background CPU, thermal state, MySQL/opcache warmth, and container scheduling all contribute multiple-ms of systematic variance between sessions, so I would not read +1.63ms as "the PR is slower." It's noise. (The +29.8ms Response Time delta confirms this — that's whole-request including network overhead and is even noisier; it's drifting in the same direction as wp-total at ~5×, consistent with environmental drift rather than the PR.) Reconciling with the call-count evidenceThe SPX run showed the optimization is structurally working (−891 lookup calls per page). My estimate was the savings would be ~100–1000µs. The benchmark confirms that the upper bound of the actual savings is under the noise floor of a 500-iteration median — which fits cleanly with my estimate. If the PR were saving 5ms per request it would show; saving 0.1–0.5ms is invisible at this signal-to-noise ratio. So the PR is:
What this means for the bigger regression huntThis is the uncomfortable truth about the wp70-vs-wp69 regression: none of the individual fixes from my earlier list will measurably move the needle on their own. The ~25–30ms total regression is genuinely composed of many ~0.1–1ms costs. Killing them one at a time will keep producing benchmark results that look exactly like this one — within noise. That has implications for the workflow:
The structural wins I called out earlier — conditionally registering the Recommendation for what to say on the PRSomething like:
The PR is correct and worth merging. Just don't expect any individual benchmark to vindicate it. |
Co-authored-by: Weston Ruter <westonruter@gmail.com>
Trac Ticket MissingThis pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook. |
Performance regression for #10777
By checking
$block['attrs']['className']first, it ensure that for the 90% of blocks that don't have custom CSS, the function returns in microseconds without ever triggering the preg_match.Use of AI Tools
N/A
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.