Repository navigation
perf: skip attribute transform for blocks no extension matches - #146
Merged
Merged
Conversation
Without a matching extension there are no definitions to transform and no code selector can be set, so return before Block::transform().
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. |
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.
Extensions::render_blocks()is arender_blockfilter for every block on the page, core blocks included. It runsBlock::transform()before it checks whether any extension matches (includes/classes/extensions.phparound 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, andhasCodeSelector(set only intransform_code_attribute()) is always false. The early return can therefore checkempty( $matches )before the transform, and the later check goes away. Output is unchanged. Theblockstudio/blocks/attributes/renderfilter 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 inBlock::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.phpcover an unmatched core block passing through unchanged, leftover code selector values on an unmatched block, and the code selector on a matched block still settingdata-assetsand printing the scoped CSS.tests/unit/extensionspasses before and after.