mozilla / standards-positions

https://mozilla.github.io/standards-positions/
Mozilla Public License 2.0
653 stars 73 forks source link

Priority Hints #606

Closed pmeenan closed 2 years ago

pmeenan commented 2 years ago

Request for Mozilla Position on an Emerging Web Specification

Other information

Priority Hints was explored in 2018 in #25 but went stale. The work has re-started now that there are cleaner use cases and the scope has been reduced to only reflect the importance of the fetch for the initial resource referenced by an element (rather than cascading to all fetches within a frame or triggered by a given script).

Chrome has been running a field trial that started in 96 and early feedback is very positive and the plan is to push forward for a launch (any feedback on keeping "importance" or finding something more fetch-specific on the linked whatwg issue above would be appreciated).

The prioritization changes under the cover as a result of developer hinting can be applied both to internal browser fetch ordering as well as plumbed through to protocol-level prioritization for multiplexed protocols that support priotitization (HTTP/2 and HTTP/3 currently).

Use Cases

There are 3 concrete use-cases that have emerged that are current developer pain points that Priority Hints provides a relatively clean solution for with minimal effort on the developer's part.

Signaling Important Images

Identifying which images are important in markup gives a parse-time signal to the browser for ordering the image fetches. Chromium already has logic that boosts the priority of visible images in the viewport but that information is only available after styles have been applied and layout has been performed which is relatively late in the lifecycle of fetching resources for the page.

We have seen early gains in the 20-40% range for Largest Contentful Paint for sites in the origin trial where they can benefit from signaling of important images (Content pages with a main hero image and product detail pages for e-commerce sites are easy wins).

Differentiating API fetches

Script using the fetch API to both react to user input (like with autocomplete suggestions based on typing) and performing background bulk fetches benefits from being able to differentiate the priorities of the fetches. In this case, it works best if the transport protocol and origin all support prioritization but it provides application-level control to make the API calls more responsive than is otherwise possible.

Signaling the priority of async scripts

Async (and defer) scripts don't block tree-building so Chromium usually assigns them a lower priority. For some sites, the core framework and application logic are all loaded through async scripts and the lower priority can harm performance. There is a chromium-specific hack that relies on preloading the same script to get it to load with a higher priority. It would be a lot cleaner to signal it directly.

bholley commented 2 years ago

These all sound like reasonable use-cases to me. @Bas-moz any thoughts?

Bas-moz commented 2 years ago

Agreed. This is reasonable. @smaug---- what do you think, you have more expertise around our page load scheduling capabilities here?

martinthomson commented 2 years ago

I've reviewed the specification. It is clearly a work in progress, and I've provided some feedback. That said, the basic idea is sound and worth investigating further. It's simple enough that it might work even, at least from how it interacts with networking.

smaug---- commented 2 years ago

The spec is obviously very initial draft so it needs quite a bit work before implementations should ship, but yes, this idea has been around for over a decade. See for example https://lists.w3.org/Archives/Public/public-webapps/2010AprJun/0885.html (looks like I even had a patch for XHR priorities https://bug559092.bmoattachments.org/attachment.cgi?id=438963 :) )

Internally Gecko has various ways to prioritize requests, and quite a few heuristics like possibly-visible-images or handling XHR/fetch in reaction to user input.

Anyhow, the idea sounds reasonable.

pmeenan commented 2 years ago

FWIW, the TAG review just completed and I'm landing the last bits of the HTML spec processing model changes this week (just plumbing the attribute through to the underlying fetch). Are there any remaining concerns with the spec?

It has been in Origin Trial with Chrome for a few months now and will likely be going for intent-to-ship in the next week or so.

smaug---- commented 2 years ago

The issues mentioned in https://github.com/whatwg/html/issues/7150 haven't been resolved. I'd really prefer to be more precise with the naming.

pmeenan commented 2 years ago

@smaug---- the name change has landed. Do you know of any other concerns with the feature/spec? Would it be possible to get an official position on it from Mozilla?

smaug---- commented 2 years ago

the DOM side of it looks now quite reasonable. @martinthomson @ddragana any comments on https://wicg.github.io/priority-hints/#effects-of-priority-hints ?

martinthomson commented 2 years ago

That stuff is mostly fine (though I might discourage HTTP/2 priority signaling rather than encouraging it as this does, it's fine).

Thanks for looking into this @smaug----, I'll put up a pull request.

martinthomson commented 2 years ago

One last thing for @pmeenan: please try to find a home for this work that isn't WICG. https://www.w3.org/webperf/ seems like a good candidate.

pmeenan commented 2 years ago

@martinthomson This work was from the web performance working group. @yoavweiss, is there something we need to do to associate the spec better?

Eventually most of it will move into html/fetch once there are 2 implementations.

martinthomson commented 2 years ago

Why is this in WICG then rather than webperf?

yoavweiss commented 2 years ago

It's in WICG as this work is still in incubation, and we didn't necessarily have 2 interested implementers. (Or even 1, in the lengthy period where we struggled to prove benefits, before Pat took over the work) But the work has been thouroughly discussed in the WebPerfWG, from its very begining.

The WG (very briefly) discussed adoption of this at TPAC, but Priority-Hints wasn't top-priority (pun not intended) for adoption at the time.

If there's interest from Mozilla, we can definitely push for WebPerfWG adoption, although, given that most of the spec's processing model is HTML and Fetch monkey-patching, direct integration would probably be better. (as @pmeenan said above)

/cc @bdekoz

smaug---- commented 2 years ago

I'd expect the proposal to be integrated somehow to the HTML and fetch specs.