Skip to content

perf: skip attribute transform for blocks no extension matches - #146

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/skip-extension-transform
Oct 22, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/skip-extension-transform

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

Extensions::render_blocks() is a render_block filter for every block on the page, core blocks included. It runs Block::transform() before it checks whether any extension matches (includes/classes/extensions.php around lines 103 to 114), and only afterwards returns early when there are no matches and no code selector.

Without a matching extension there are no attribute definitions, so transform() cannot run a code field, and hasCodeSelector (set only in transform_code_attribute()) is always false. The early return can therefore check empty( $matches ) before the transform, and the later check goes away. Output is unchanged. The blockstudio/blocks/attributes/render filter no longer runs for leftover Blockstudio attributes on blocks no extension matches; their results were discarded before.

The saving is small on native PHP: about 0.5 ms per 300 core blocks in a micro benchmark. It is much larger in runtimes with a coarse clock such as WordPress Playground, where the uniqid() call in Block::id() waits about 1 ms per block (about 440 ms down to 1 ms for 300 blocks).

The new tests in tests/unit/extensions/ExtensionRenderBlocksTest.php cover an unmatched core block passing through unchanged, leftover code selector values on an unmatched block, and the code selector on a matched block still setting data-assets and printing the scoped CSS. tests/unit/extensions passes before and after.

Without a matching extension there are no definitions to transform and no
code selector can be set, so return before Block::transform().
@dnnsjsk
dnnsjsk merged commit 7b0a3c6 into inline0:main Oct 22, 2026
@dnnsjsk

dnnsjsk commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Included in Blockstudio 7.7.6, now officially released. This PR is merged into main as part of the reviewed release, with full CI and distribution checks passing for the release commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants