#58235 closed enhancement (fixed)
Enhance hero image loading performance with Fetchpriority
Reported by: | flixos90 | Owned by: | flixos90 |
---|---|---|---|
Milestone: | 6.3 | Priority: | high |
Severity: | normal | Version: | |
Component: | Media | Keywords: | has-patch commit has-dev-note add-to-field-guide |
Focuses: | performance | Cc: |
Description
The fetchpriority
attribute is a standard HTML attribute that allows annotating resources (e.g. images, scripts, stylesheets, ...) on a web page to give them a certain priority.
While the attribute can be used on different resources, this ticket is scoped to images only. Using the fetchpriority
attribute is recommended with a value of “high” on the most important image on a page, which is an important performance best practice that improves LCP performance.
Please see the proposal post for additional context.
As mentioned in the post, support for fetchpriority
on images should be implemented relying on similar logic as lazy-loading images uses. Yet, the two attributes need to function on their own, e.g. even sites that disable lazy-loading should be able to use Fetchpriority. Therefore the engineering effort to support the fetchpriority
attribute will involve decoupling that logic from the loading
attribute.
Last but not least, it should also be highlighted that, since fetchpriority
can be used on other elements on images, we should consider that for the implementation. Certain parts of the implementation may be specific to images while other parts may apply to fetchpriority
on any resource.
Change History (42)
This ticket was mentioned in Slack in #core-media by antpb. View the logs.
17 months ago
#2
@
16 months ago
- Milestone changed from Awaiting Review to 6.3
- Owner set to flixos90
- Priority changed from normal to high
- Status changed from new to assigned
This ticket was mentioned in PR #4495 on WordPress/wordpress-develop by kt-12.
16 months ago
#3
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/58235
This ticket was mentioned in Slack in #core by oglekler. View the logs.
16 months ago
This ticket was mentioned in Slack in #core by chaion07. View the logs.
16 months ago
This ticket was mentioned in Slack in #core-test by boniu91. View the logs.
16 months ago
@flixos90 commented on PR #4495:
15 months ago
#7
@kt-12 In https://github.com/WordPress/wordpress-develop/pull/4495/commits/2405a5a44740e42cdc82c2952e67265e71ead0a1, I pushed a few changes to ensure the existing iframe logic doesn't call the now deprecated wp_get_loading_attr_default()
function:
wp_iframe_tag_add_loading_attr()
now uses the new function.- The new function now works for
iframe
tags too. - The private functions were enhanced with a
$tag_name
parameter, per my last code review feedback. - For
iframe
tags, the fetchpriority private function returns early because we don't want to handle that yet. - A
TODO
comment was added inwp_iframe_tag_add_loading_attr()
to eventually call the function in a cleaner way, however the dimension do not matter at this point, so parsing out the actual image dimensions would be wasteful for now. It's a bit weird, but as long as there's a comment explaining it, it's okay to have in there. Once we addfetchpriority
support for iframes in the future, that'll be removed.
@spacedmonkey commented on PR #4495:
15 months ago
#8
@spacedmonkey commented on PR #4495:
15 months ago
#9
Doing benchmarks, I can also see performance regeneration.
Benchmark, TT3, 500 runs. Tested with post block gallery ( from
Trunk
Response Time (median),97.08
wp-load-alloptions-query (median),0.6
wp-before-template (median),47.64
wp-before-template-db-queries (median),3.75
wp-template (median),42.53
wp-total (median),90.17
wp-template-db-queries (median),4.23
PR
Response Time (median),99.34
wp-load-alloptions-query (median),0.6
wp-before-template (median),47.21
wp-before-template-db-queries (median),3.68
wp-template (median),44.72
wp-total (median),92.39
wp-template-db-queries (median),4.22
@spacedmonkey commented on PR #4495:
15 months ago
#10
@flixos90 commented on PR #4495:
15 months ago
#11
@spacedmonkey Good point. While eventually it would be great to refactor all of wp_filter_content_tags()
to use WP_HTML_Tag_Processor
, right now we're only doing it in a single place, partially, so maybe in that case that leads to a performance regression.
We should probably try to replace that code with regular expressions to get the attribute values and see if that gets rid of the regression. That's not as nice-looking code for sure, but nice-looking code is not as important as performance.
It also doesn't mean that WP_HTML_Tag_Processor
in general is slow, but probably the way we use it here, mixed with regular expressions, is probably not efficient.
joemcgill commented on PR #4495:
15 months ago
#12
I think it was a good idea to give the WP_HTML_Tag_Processor
approach a try here, and really instructive to see that it seems to be slower than manipulating the HTML string manually. I agree that we should go back to the regex approach used in other places and do another comparison.
@spacedmonkey commented on PR #4495:
15 months ago
#13
@kt-12 If you can revert using WP_HTML_Tag_Processor
and replace with regex<, I will return profiles again. We can then compare the three profiles and see what the overhead of using WP_HTML_Tag_Processor
is.
15 months ago
#15
@kt-12 If you can revert using
WP_HTML_Tag_Processor
and replace with regex<, I will return profiles again. We can then compare the three profiles and see what the overhead of usingWP_HTML_Tag_Processor
is.
@spacedmonkey I have replaced it with regex (commit), you can try profiling now. cc: @felixarntz
@flixos90 commented on PR #4495:
15 months ago
#16
@kt-12 As discussed earlier, I pushed a few commits, some with miscellaneous test fixes following review, but most importantly:
- https://github.com/WordPress/wordpress-develop/pull/4495/commits/2e69f10a14db9e3c682f2d0378652bb46cd0060b adds integration tests for
wp_get_attachment_image()
and howwp_get_loading_optimization_attributes()
is used in that function. - https://github.com/WordPress/wordpress-develop/pull/4495/commits/20dbc85c9883961c3a2202536ad0548bc01813f9 adds test coverage for
wp_maybe_add_fetchpriority_high_attr()
.
The main piece of work left to do now is to replicate the existing test coverage for the deprecated wp_get_loading_attr_default()
function for the new wp_get_loading_optimization_attributes()
function. For the most part, you can probably copy the existing tests and update them to rely on the new function.
@spacedmonkey commented on PR #4495:
15 months ago
#17
@kt-12 This PR needs a rebase.
#18
@
15 months ago
I have done profiling and benchmarking on this PR.
Benchmark - TT theme - 500 runs - Theme test data - gallery post.
Trunk - 55962 | PR - a2c977f | |
Response Time (median) | 56.29 | 55.96 |
wp-load-alloptions-query (median) | 0.62 | 0.62 |
wp-before-template (median) | 18.56 | 18.43 |
wp-before-template-db-queries (median) | 1.35 | 1.35 |
wp-template (median) | 30.46 | 30.31 |
wp-total (median) | 49.17 | 48.93 |
wp-template-db-queries (median) | 5.58 | 5.53 |
Here are comparison using blackfire.
This PR is showing a net benefit to php performance. Which is a nice side effect.
@thekt12 @flixos90
#19
@
15 months ago
- Keywords needs-dev-note added
This ticket was discussed in the recent performance bug scrub.
needs-dev-note
added for new feature.
Props to @joemcgill @spacedmonkey
@spacedmonkey commented on PR #4495:
15 months ago
#20
@kt-12 Can you rebase this PR. Once done, i will re-review and re-profile.
@flixos90 commented on PR #4495:
15 months ago
#22
Committed in https://core.trac.wordpress.org/changeset/56037 🎉
This ticket was mentioned in PR #4756 on WordPress/wordpress-develop by @flixos90.
15 months ago
#24
@flixos90 commented on PR #4756:
15 months ago
#25
cc @kt-12
@flixos90 commented on PR #4756:
15 months ago
#27
Committed in https://core.trac.wordpress.org/changeset/56112
This ticket was mentioned in PR #4766 on WordPress/wordpress-develop by @spacedmonkey.
15 months ago
#29
Trac ticket: https://core.trac.wordpress.org/ticket/58235
Follow on from https://core.trac.wordpress.org/changeset/56037.
Move the check to see if properties exist before doing anymore processing.
@spacedmonkey commented on PR #4766:
15 months ago
#32
@felixarntz Good catch. Sorry I missed that comment how. Closing this PR.
#33
@
15 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening due to a small bug that [56037] reintroduced after [55825] / #58089 had fixed it: Programmatically injected images within post content (the_content
filter) should be skipped except when the the_content
context is used so that they are only considered once, as part of the whole post content blob.
[55825] fixed that, but then the refactoring as part of this ticket accidentally added the postprocessing logic call to that clause so that now such images may incorrectly receive fetchpriority="high"
when they should not.
See https://core.trac.wordpress.org/ticket/58681#comment:13, which originally discovered this regression.
This ticket was mentioned in PR #4800 on WordPress/wordpress-develop by @flixos90.
15 months ago
#34
Trac ticket: https://core.trac.wordpress.org/ticket/58235
See https://core.trac.wordpress.org/ticket/58235#comment:33: This fixes a regression related to what was originally fixed by https://core.trac.wordpress.org/changeset/55825.
@flixos90 commented on PR #4800:
15 months ago
#35
@kt-12 @spacedmonkey Could you please take a look?
#37
@
15 months ago
- Keywords commit added
Thanks @flixos90, The PR got enough approval for merge.
commit
. keyword added for consideration.
@flixos90 commented on PR #4800:
15 months ago
#39
Committed in https://core.trac.wordpress.org/changeset/56164
Milestoning this for 6.3 and as a high priority for the performance team, given that this is part of our team roadmap.