[wp-trac] [WordPress Trac] #59490: Performance issues in _register_theme_block_patterns

WordPress Trac noreply at wordpress.org
Thu Sep 28 16:54:33 UTC 2023


#59490: Performance issues in _register_theme_block_patterns
--------------------------+--------------------
 Reporter:  spacedmonkey  |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  6.4
Component:  Editor        |    Version:  6.0
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+--------------------
 During the testing of the TT4 theme in preparation for the WordPress 6.4
 release, it came to our attention that the _register_theme_block_patterns
 function is imposing a significant resource overhead. This issue primarily
 stems from themes, such as TT4, that register a substantial number of
 block patterns. These patterns necessitate numerous file operations,
 including file lookups, file reading into memory, and related processes.
 To provide an overview, the _register_theme_block_patterns function
 currently performs the following file operations:

 - is_dir
 - is_readable
 - file_exists
 - glob
 - file_get_contents (utilized via get_file_data)

 Additionally, the function reads the entire pattern into memory through an
 inclusion process. However, it is important to note that these pattern
 files remain unchanged unless theme files are modified or updated.
 Consequently, conducting these file operations on every page request
 appears unnecessary and contributes to increased resource consumption.

 To address this issue, we propose the implementation of caching mechanisms
 and lazy loading techniques within the _register_theme_block_patterns
 function. This optimization will substantially reduce the frequency of
 file lookups, enhance performance, and alleviate the resource-intensive
 nature of the function.

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


More information about the wp-trac mailing list