#58319 closed enhancement (fixed)
Improve performance of get_block_theme_folders
Reported by: | spacedmonkey | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | 6.4 | Priority: | normal |
Severity: | normal | Version: | 5.9 |
Component: | Themes | Keywords: | has-patch needs-testing commit needs-dev-note |
Focuses: | performance | Cc: |
Description
The function get_block_theme_folders can be called a lot in a template load. This function contains 2 file_exists
checks. This can be slow, as it is accessing the file system.
Attachments (1)
Change History (27)
This ticket was mentioned in PR #4456 on WordPress/wordpress-develop by @spacedmonkey.
16 months ago
#2
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/58319#ticket
#3
@
16 months ago
@swissspidy I have looked into is_dir. It is faster, but not by much. It this still the same code that is 20+ per page and it results in overhead.
#5
@
16 months ago
Benchmarks run 1000 times against TT3 theme.
Trunk | PR | |
Response Time (median) | 127.75 | 118.17 |
wp-load-alloptions-query (median) | 5.06 | 5.09 |
wp-before-template (median) | 64.99 | 61.77 |
wp-before-template-db-queries (median) | 5.67 | 5.28 |
wp-template (median) | 57.21 | 51.32 |
wp-total (median) | 123.3 | 113.31 |
wp-template-db-queries (median) | 3.38 | 3.06 |
This ticket was mentioned in Slack in #core by oglekler. View the logs.
13 months ago
#8
@
13 months ago
- Keywords needs-testing added
The patch needs to be tested:
- That everything is working as before,
- That there is a performance improvement.
And this is an enhancement, so, 19 days to be in trunk to get into 6.4.
This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.
13 months ago
This ticket was mentioned in Slack in #core-performance by thekt12. View the logs.
12 months ago
This ticket was mentioned in Slack in #core-performance by thekt12. View the logs.
12 months ago
This ticket was mentioned in PR #5202 on WordPress/wordpress-develop by @thekt12.
12 months ago
#13
Trac ticket: https://core.trac.wordpress.org/ticket/58319
closes #4456
This ticket was mentioned in Slack in #core-performance by mukeshpanchal27. View the logs.
12 months ago
This ticket was mentioned in Slack in #core by oglekler. View the logs.
12 months ago
@spacedmonkey commented on PR #5202:
12 months ago
#16
@kt-12 Please check https://github.com/WordPress/wordpress-develop/pull/3629/files to check how caching was added here.
This ticket was mentioned in Slack in #core-performance by thekt12. View the logs.
12 months ago
@flixos90 commented on PR #4456:
12 months ago
#18
Closing in favor of #5202
@spacedmonkey commented on PR #5202:
12 months ago
#19
I am going to wait until @costdev reviews before committing this.
is_dir()
is much faster thanfile_exists
for checking directory existence. On the other hand,file_exists()
also checks if the directory can be accessed. See https://bugs.php.net/bug.php?id=78285So replacing
file_exists( $theme_dir . '/block-templates' )
withis_dir( $theme_dir . '/block-templates' )
would be faster. Maybe withis_dir( $theme_dir . '/block-templates' ) && is_readable( $theme_dir . '/block-templates' )
to have the same effect.Aside: makes me wonder why the following code uses all three checks:
https://github.com/WordPress/wordpress-develop/blob/c40e0c6f816ed27ba8b75462632498a36f624181/src/wp-includes/block-patterns.php#L374-L377
That seems like overkill.