Skip to content

Avoid repeatedly parsing block HTML when extracting attributes - #128

Merged
ingeniumed merged 1 commit into
trunkfrom
ingeniumed/audit-04-dom-reuse
Nov 19, 2026
Merged

ingeniumed merged 1 commit into
trunkfrom
ingeniumed/audit-04-dom-reuse

Conversation

@ingeniumed

Copy link
Copy Markdown
Contributor

Description

The parser currently builds a new DOM from a block’s HTML for every sourced attribute. A block with several attributes therefore repeats the same HTML parsing work within one API request. Metadata attributes also construct a DOM even though their values come from post metadata.

Create the DOM only when an HTML-sourced attribute needs it, then reuse it for the remaining attributes of that block. Read metadata directly without constructing a DOM. Each block keeps its own DOM; none is shared across blocks or requests.

Scenario Before After
Several HTML-sourced attributes on one block Parse the same HTML for each attribute Parse once and reuse the DOM
Metadata-only attributes Build a DOM before reading metadata Read metadata without parsing HTML

The change is intended to preserve attribute values, selector behavior, defaults and response structure. Tests and direct comparisons with trunk matched across the exercised fixtures. A synthetic benchmark showed roughly 3× faster parsing.

Screenshots are not applicable to this API change.

Steps to Test

Run against WordPress 6.8, 6.9 and 7.1:

composer phpcs
composer test
composer test-multisite

Regression tests check exact values with mixed attribute sources, reversed source declaration order, query ordering, entities, raw markup and metadata defaults.

@ingeniumed
ingeniumed requested a review from a team as a code owner November 18, 2026 02:43
@ingeniumed ingeniumed self-assigned this Nov 18, 2026

@alecgeatches alecgeatches left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a safe optimization, thanks!

@ingeniumed
ingeniumed merged commit c53fbaf into trunk Nov 19, 2026
20 checks passed
@ingeniumed
ingeniumed deleted the ingeniumed/audit-04-dom-reuse branch November 19, 2026 19:39
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