#57057 closed task (blessed) (fixed)
Reduce usage of `wp_get_theme`
Reported by: | spacedmonkey | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | 6.1.1 | Priority: | normal |
Severity: | normal | Version: | 6.1 |
Component: | Themes | Keywords: | has-patch has-screenshots commit fixed-major |
Focuses: | performance | Cc: |
Description
The function wp_get_theme
function returns an instance of WP_Theme
instance. Creating an instance of this class uses resources. In many cases this is not needed, as a single property is used. Lowering usage will save CPU cycles.
Attachments (4)
Change History (23)
This ticket was mentioned in PR #3599 on WordPress/wordpress-develop by @spacedmonkey.
2 years ago
#1
- Keywords has-patch added
#3
@
2 years ago
@spacedmonkey It looks like one of the changes needs to be submitted upstream to Gutenberg.
There are definitely some instances where removing wp_get_theme()
may be appropriate, and this seems like a great improvement at the surface. But I wonder if there's a better way since this does not address the root problem that creating instances of WP_Theme
can be resource intensive. But what about reworking WP_Theme
to have a get_instance()
method that's called by wp_get_theme()
(similar to what is done for posts, terms, comments, etc.) and using the Cache API?
This also feels like a major release change rather than a minor one to me. I'm going to leave it in 6.1.2 for now and will let the folks leading that release make the final call, but I recommend waiting for 6.2 for including this.
#4
@
2 years ago
- Keywords needs-unit-tests added
@spacedmonkey Doesn't really need many unit tests, but one unit test to cover the change in supported method parameter value would be useful.
@desrosj For me, most of this is reasonable to land in 6.1.x as it's trivial replacements of wp_get_theme()->get_stylesheet()
with get_stylesheet()
which is good for performance. However, changing the supported values for a method parameter, despite being backward compatible, strictly speaking would go beyond a 6.1.x. Though I don't have a strong opinion either way.
#5
follow-up:
↓ 6
@
2 years ago
@flixos90 Changing the get_user_data_from_wp_global_styles
is the biggest change in this patch. If we remove that, I think can commit in 6.1.x.
This is a trival change as it a function replacement and drop-in solution.
#6
in reply to:
↑ 5
@
2 years ago
Replying to spacedmonkey:
@flixos90 Changing the
get_user_data_from_wp_global_styles
is the biggest change in this patch. If we remove that, I think can commit in 6.1.x.
This is a trival change as it a function replacement and drop-in solution.
SGTM. In that case, it doesn't need unit tests either.
#7
@
2 years ago
I think if the change to get_user_data_from_wp_global_styles
is removed, we could look at including this in 6.1.1.
#9
@
2 years ago
@peterwilsoncc @flixos90 @desrosj I have scaled back to the PR, so it just does drop-in replacements of one function to another.
Please review. I have provided before and after numbers.
#10
@
2 years ago
- Keywords commit added; changes-requested removed
- Milestone changed from 6.1.2 to 6.1.1
Thanks @spacedmonkey! Looks good. I say let's include this improvement in 6.1.1.
#12
@
2 years ago
- Owner set to spacedmonkey
- Resolution set to fixed
- Status changed from new to closed
In 54817:
#13
@
2 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for backport to 6.1.1.
@spacedmonkey commented on PR #3599:
2 years ago
#17
Committed
Trac ticket: https://core.trac.wordpress.org/ticket/57057