Skip to content

Themes: Record the registered blocks on the first theme.json origin build - #14077

Open
sirreal wants to merge 3 commits into
WordPress:trunkfrom
sirreal:theme-json/seed-registry-guard
Open

sirreal wants to merge 3 commits into
WordPress:trunkfrom
sirreal:theme-json/seed-registry-guard

Conversation

@sirreal

@sirreal sirreal commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Avoid rebuilding WP_Theme_JSON_Resolver data on the second call to each origin getter. The first call skips has_same_registered_blocks() because the data cache is empty, leaving the block registry cache unset. The next call treats that as a registry change and rebuilds the data.

Check the registered blocks before the data cache in all four getters. This records the registry on the first call so the second reuses the data. Registering a new block still triggers a rebuild; get_theme_data() still applies theme supports on each call by default.

Filters added after the first build now need wp_clean_theme_json_cache() to take effect unless a new block is registered. The redundant rebuild previously picked them up on the second call. Automatic invalidation on filter changes remains unresolved in Trac #62249.

In measurements from 2026-10-07, this change reduced origin builds from eight to four per request, saving 0.5–1.2 ms in the getters. Total request time was too variable to establish an improvement. Getter times in milliseconds, from three rounds of 20 requests each (medians after warm-up):

Request Trunk Branch
Front page 5.07 / 5.47 / 5.20 4.53 / 4.55 / 4.57
Single post 3.76 / 4.12 / 3.78 3.17 / 3.20 / 3.19
wp/v2/posts?context=edit 11.02 / 11.51 / 11.07 10.32 / 10.27 / 10.47

Runs alternated trunk and branch in Docker with PHP 8.3.33, WordPress 7.2-alpha-63166-src, WP_DEBUG off, and Twenty Twenty-Four with ten block-content posts. These measurements predate the merged-data cache added in r64354.

Validation at d52f8b9a38: 44 resolver tests (177 assertions) and the themes and blocks groups (1,297 tests, 10,679 assertions, 15 skips) passed, as did PHPCS for both files. The four new regression cases cover cache reuse and invalidation; all fail against the pre-fix resolver. The existing core-data test now sets both caches as its data provider specifies.

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

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code, Codex
Model(s): Claude Fable 5.1, GPT-6
Used for: Implementation, tests, measurement, review and description editing.


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.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

…uild.

WP_Theme_JSON_Resolver::get_core_data(), get_block_data(), get_theme_data() and get_user_data() tested the cached object for null before calling has_same_registered_blocks(). On the first call the object is null, so the check never ran and never recorded the registered blocks. The second call ran the check, found nothing recorded, and rebuilt the origin's data.

Call has_same_registered_blocks() first, so the first build records the registered blocks and the second call reuses the data. A block type registered between calls still rebuilds it.

The test data provider case "When both caches are not empty" left the blocks cache empty and expected a rebuild; it now fills the cache and expects none.
@sirreal
sirreal force-pushed the theme-json/seed-registry-guard branch from 205c3da to c80fcb0 Compare October 9, 2026 12:08
@sirreal
sirreal marked this pull request as ready for review October 9, 2026 12:23
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@sirreal
sirreal requested a review from mreishus October 19, 2026 09:45
@sirreal

sirreal commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

The performance numbers in the description are probably all much lower, to the point that this change is almost certainly negligible in terms of performance, since #14071 landed.

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.

1 participant