Skip to content

Cache parse of block in block patterns - #5421

Draft
spacedmonkey wants to merge 9 commits into
WordPress:trunkfrom
spacedmonkey:fix/parse-patterns
Draft

spacedmonkey wants to merge 9 commits into
WordPress:trunkfrom
spacedmonkey:fix/parse-patterns

Conversation

@spacedmonkey

Copy link
Copy Markdown
Member

Trac ticket: https://core.trac.wordpress.org/ticket/59541


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.

@spacedmonkey
spacedmonkey requested review from gziolo and ockham October 6, 2023 14:56
@gziolo

gziolo commented Oct 6, 2023

Copy link
Copy Markdown
Member

In my testing #5399, I also extracted the logic for updating the content of the pattern to a new method. I was validating other refactoring, though. So, both PRs separately could potentially improve performance.

@ockham

ockham commented Oct 9, 2023

Copy link
Copy Markdown
Contributor

This is a promising approach 🤔 Maybe I closed the ticket too early 😅 (although arguably, this PR does something different than what the ticket says, so it might be worth filing a new one).

Let's maybe run some numbers on this one, and rebase it once @gziolo's #5399 lands (in order to use the extracted parsing and hooked blocks insertion logic).

return array_values( $patterns );
}

protected function get_parse_blocks( $pattern ) {

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.

Nitpick, we might want a different name for the method, as it not only parses the content but also (conditionally) inserts hooked blocks, and returns re-serialized markup.

(Per #5421 (comment), we might just use pepare_content from #5399 as name.)

@felixarntz

Copy link
Copy Markdown
Member

@spacedmonkey Now that #5399 has been committed, there is a merge conflict here. Could you please address it?

Curious to run benchmarks on this once it's up to date with latest trunk.

@spacedmonkey

Copy link
Copy Markdown
Member Author

@spacedmonkey Now that #5399 has been committed, there is a merge conflict here. Could you please address it?

Curious to run benchmarks on this once it's up to date with latest trunk.

I will provide benchmarks tomorrow.

@spacedmonkey

Copy link
Copy Markdown
Member Author

So after some testing, it seems like there is little performance benefit from this change now. All the performance benefit seems to have been committed in #5399.

This PR might be useful for times where there the same pattern is used multiple times on a page. Not in all the example themes I found, I could not find an example where it did this. I am also worried that the filters would not run if this result was cached.

I still think there is something here, but it needs more work and is unlikely to make it's way into core in this release. Closing for now.

@gziolo

gziolo commented Oct 10, 2023

Copy link
Copy Markdown
Member

I see that the ticket got reopened. It would be great to run the benchmarks again with the latest trunk. Related Slack comment with a better context (accessing the link might require registration at https://make.wordpress.org/chat/):
https://wordpress.slack.com/archives/C02RQBWTW/p1696950609355169?thread_ts=1696880738.627909&cid=C02RQBWTW .

@gziolo
gziolo removed their request for review July 10, 2026 09: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.

4 participants