Improved PHP performance for core blocks registration

Early block.json Registration Method

Starting with WordPress 5.8, extenders were encouraged to begin to utilize block.json to register blocks through a unified registration process. The benefits offered by this update provide consistency and convenience when registering blocks through PHP or JavaScript.

However, while this block.json scanning convention is extremely convenient, it does add additional processing when core blocks are instantiated. On each page load, block registration undergoes the following steps:

  • Scan folders for block.json files.
  • When a block.json file is found, read its contents into memory.
  • Call json_decode on the file contents to convert it to a PHP array.
  • Register the block using the decoded data.

With over 70 core block files to scan and load, this presented an opportunity for optimization.

Core Block Registration Update

To reduce filesystem reads and processing of block.json files, which should benefit all WordPress sites and improve performance, block registration has been updated to:

  • Introduce a new Grunt task (copy:block-json) that scans and converts core block.json files to PHP arrays and stores them in a single blocks-json.php at build time.
  • Use the new blocks-json.php file in the register_block_type_from_metadata() function.
  • Assign the block registration data to a static variable (cache) so that it’s only loaded once per request.

The addition of an extra build task to compile the decoded JSON data to PHP reduces block registration filesystem reads from ~70 files to just a single file. And since blocks-json.php is a native PHP array, it can be used directly without additional conversion.

The conversion from block.json files to PHP arrays is achieved through the json2php package, which is already utilized in Core and Gutenberg.

References

Props to @aristath for source material and collaboration, and to @milana_cap for review of this dev note.

#6-1, #dev-notes, #performance

A WordPress Commenter

Recent Posts

WordPress 7.1 Beta 3

WordPress 7.1 Beta 3 is ready for download and testing!  This beta release is intended…

3 days ago

WordPress 7.0.2 Release

WordPress 7.0.2 is now available. The 7.0.2 security release addresses one critical and one high…

1 week ago

WordPress 7.1 Beta 1

WordPress 7.1 Beta 1 is ready for download and testing!  This beta release is intended…

1 week ago

Performance Chat Summary: 14 July 2026

The full chat log is available beginning here on Slack. WordPress Performance Trac tickets @westonruter…

2 weeks ago

Your Guide to WordCamp US 2026

August 16-19, 2026 | Phoenix Convention Center, Phoenix, Arizona WordCamp US 2026 returns for another…

2 weeks ago

WordPress 7.0.1 Maintenance Release

WordPress 7.0.1 is now available! This minor release includes fixes for 31 bugs throughout Core and the Block…

2 weeks ago