Block Hooks: Skip parsing and re-serializing post content in the_content when no blocks are hooked - #14022
Open
sboisvert wants to merge 2 commits into
Open
Block Hooks: Skip parsing and re-serializing post content in the_content when no blocks are hooked#14022sboisvert wants to merge 2 commits into
the_content when no blocks are hooked#14022sboisvert wants to merge 2 commits into
Conversation
|
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. |
westonruter
reviewed
Oct 5, 2026
| } | ||
| } | ||
|
|
||
| $parser_calls = 0; |
Member
There was a problem hiding this comment.
You can use the MockAction class for this instead. It has a method that gets the call count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pages with a lot of block content are slow because, since 6.8, every
the_contentcall parses and re-serializes the whole post even when no block is hooked. Since [60173] (6.8.1), the temporaryhooked_block_typesfilter also makes thehas_filter( 'hooked_block_types' )check inapply_block_hooks_to_content()always true on this path, so the per-block Block Hooks run on top of that.Timing
apply_block_hooks_to_content_from_post_object()on ~1 MB of block markup with nothing hooked (PHP 8.4): 34-35 ms per call on trunk, 0.4 ms with this change.This change returns the content unchanged at the top of
apply_block_hooks_to_content_from_post_object(), before the temporary filter is added, when all of these are true:get_hooked_blocks()is empty andhas_filter( 'hooked_block_types' )is false;has_block( 'core/template-part', $content )is false;$ignored_hooked_blocks_at_rootis null (the REST API passes an empty array, so REST requests still get the full parse; see #65008).Rendered output is unchanged, except for content that begins with a stray closing block delimiter. Since 6.8, the function wraps the post content in a temporary wrapper block before parsing, and that wrapper absorbs a leading stray closer, so the blocks after it render. With this change, such content renders as it did before 6.8.
Adds
test_apply_block_hooks_to_content_from_post_object_returns_content_unchanged_if_no_hooked_blockstoapplyBlockHooksToContentFromPostObject.php. Run withphp vendor/bin/phpunit --group block-hooks.Trac ticket: https://core.trac.wordpress.org/ticket/66236
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code, Codex CLI
Model(s): Claude Opus 5.5, GPT-6 Astra
Used for: root-cause analysis, git history checks, patch, test and benchmark drafting, accuracy review;
I reviewed the patch and the claims.