[wp-trac] [WordPress Trac] #55005: Improve PHP performance for block.json files

WordPress Trac noreply at wordpress.org
Mon Jan 31 10:12:03 UTC 2022


#55005: Improve PHP performance for block.json files
-------------------------+-----------------------------
 Reporter:  aristath     |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:  performance  |
-------------------------+-----------------------------
 Ticket initially created in
 https://github.com/WordPress/gutenberg/issues/37611, but this will
 probably need to be done in WP-Core instead, so cross-posting here.

 The `block.json` convention is extremely convenient, however it does add a
 few extra steps when core blocks get instantiated:
 * We go through folders and look for `block.json` files
 * When we locate a file, we read its contents
 * `json_decode` the file contents
 * Register the block using the decoded data

 All these things happen on **each page load**. We could improve the
 performance and save some processing for all sites by doing one of 2
 things:
 * Cache the data for blocks
 * Add an extra task in our compilers, saving the decoded JSON data as a
 PHP array

 Caching the data can be a little complicated because we'd still need to
 check the JSON file on each page-load to make sure there have been no
 changes to the file (maybe using a `filemtime` call - which would still be
 more effective than reading the file contents & decoding it). Caching
 would also require a DB call - which would still be better than the
 current processes that run, but not as optimal as the alternative below.

 Adding an extra task and compile the decoded JSON data as a PHP array
 seems like a better choice. It would be a lot easier to parse a native PHP
 array on each page-load, and we can also take care of development tasks
 etc.
 We already use the `json2php` package in Gutenberg & Core, so adding a new
 task for this should not be a difficult task.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55005>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list