#676: renderPriority element attribute
Discussions
Comment by @andruud Sep 24, 2021 (See Github)
The arguments for preferring a HTML attribute for this seem pretty weak so far, https://github.com/WICG/display-locking/issues/200#issuecomment-926450085. (Perhaps there are other unspoken arguments)?
Comment by @vmpstr Sep 24, 2021 (See Github)
The arguments for preferring a HTML attribute for this seem pretty weak so far, WICG/display-locking#200 (comment). (Perhaps there are other unspoken arguments)?
I left some more thoughts on that issue, but I would definitely appreciate TAG's view on it
Discussed
Oct 1, 2021 (See Github)
Lea: not sure I understand the use case
Kenneth: you have a lot of .. rendering today virtual scrolling - now you can do search in page - and you know that yiu're going to render soon. It's a way to request rendering...
Lea: for pre-rendering of subtrees.
Rossen: It's the oppososite of pre-rendering. not rendering as much as possible - but being ready to paint... There are many different ways you can scroll something into view or close to the view... ways to understand when something is close to the visible viewport... everything else from API point of view is not supposed to be effected. Where things come into friction is to do with accessibility. A different view on top of DOM. Not the same as the render view. In order to complete the correct view .. you need info ready. With this technique in fact some web pages that are too large to hold with a screen reader... this approach will help because you're now reducing the amount of info that goes to the screen reader. Where I pushed back on this - and opened up a design principle issue (new features shouldn't rbeak existing ones) if you want to enumerate all the headings in a doc you can do this today regardless if the heading is visible or not - but here that promise is broken. Things can be parsed but not ready for the accessibility ... So it's a game of trades... Fine line is - how much of a bennefit vs the accessibility risks... We've come a long way in the discussions in various places... The current proposal is mostly there - one remaining issue which is pertaining to one particular value - that still has open discussion. The rest of it .. worked out. It's beneficial to users of regular media as well as those using assistive tech. Grealy improves experience from CPU, memory PoV.
Lea: Why is this a HTML attribute and not a CSS property?
Rossen: we had a long discussion and took it out of CSS and that was feedback that came partially from TAG at the time... It was a CSS wg decision after a long conversation.
Ken: that would be great to know... people will ask.
Peter: sounds like the feature can defer computation of style...
Ken: right and now you can set the priority - that's good for battery performance UX.
Peter: but if you're not computing style on the unrendered content then it can't be a CSS property. At some point the parent will be the root...
Lea: defering rendering doesn't mean necessarilly defering parsing of CSS...
Peter: you don't have to compute style if you know e.g. it's off-screen. You can say "i want to compute the login controls first and the ads last".
Lea: since you have to parse stylesheets anyway...
Peter: you do have to parse but you don't have to match selectors. Seperate computation than parsing the stylesheet. HTML attribute can say "deprioritize this".
Lea: but if you don't compute the selectors...
Peter: if it was a CSS property then you'd have to do the selector matching - that's why it's an attribute.
[some discussion on this point]
Lea: another question - how are authors supposed to use it? Are you supposed to set it on elements or change it when you want it to render?
Ken: you set it beforehand.
Rossen: right.
Ken: but for web components - it would be annoying to have to set this for every element...
Peter: you don't have to set it for everything - this is something you "set and forget".
Ken: in some cases for components you need to set it in many places...
Dan: who is intended to use this? I'm hearing adding complexity to the web platform for a marginal nanosecond gains in performance?
Ken: the display login teams.. web components.. working on small features on the web that you can build web components, scroll in list, find in page, that are going to be really fast. They dont' expect everyone to do their own. If it's not something everyone is going to do and use these componants it's going to be super fast. Have an API that they set globally for every componant of that type. Instead of putting it on the devs using the custom element
Peter: I hear you but not sufficient. Just because an element is used for certain types of things doesn't tell you how it's being used. A custom input could be used for two different things in one page
Ken: change the default.. you can change it if you know what you're doing
Peter: that's reasonable
Lea: how does this attribute behave when nested? render priority user blocking..
Peter: good question - you can increase priority down the tree but increasing priority gets weird?
Dan: what is stopping someone providing third party content through an api (eg. an ad) from saying my ads are the most high priority thing? From hijacking?
Ken: very good point
Lea: also share Dan's concerns about adding complexity with nanoseconcds. Not clear to me the perf gain. Nanoseconds, miliseconds? On a sufficiently large app, what kind of gains?
Peter: I'm thinking about huge pages, understand where it could be seconds
Comment by @kenchris Oct 13, 2021 (See Github)
Will there be a way to set a default for this, say for a custom element?
Comment by @LeaVerou Oct 13, 2021 (See Github)
How does this work with nesting? E.g. if I have an ancestor with renderpriority="background"
and a descendant with renderpriority="user-blocking"
, doesn't that effectively cancel the ancestor's renderpriority
, since the ancestor would need to be rendered to render the descendant?
Wouldn't that also enable advertisers from just injecting HTML with renderpriority="user-blocking"
to hog resources for their ads?
I would also have liked a discussion on what kind of performance gain would this enable, for a sufficiently complex DOM (e.g. the HTML spec). Are we increasing the complexity of the web platform to save some nanoseconds or is it a more significant gain?
An example use case is optimizing the speed of single-page-application navigations. If the application can predict a likely user action, then it can prerender the next view offscreen via content-visibility: hidden plus renderpriority. This will make the single-page application navigations faster for the user.
How would an author use renderpriority
to enable this use case? What value would they use? Are they supposed to change the value before navigation?
Comment by @vmpstr Oct 13, 2021 (See Github)
Thank you for you feedback and questions!
Will there be a way to set a default for this, say for a custom element?
We don't have plans to expose a way to set a default behaviour. One of the alternatives that @andruud suggested is to use a CSS property instead of an Element attribute. This would allow you to target more than one element, effectively setting a default behaviour. As the issue talks about, I'd like to get TAG guidance on whether the attribute or property is more appropriate here.
How does this work with nesting? E.g. if I have an ancestor with
renderpriority="background"
and a descendant withrenderpriority="user-blocking"
, doesn't that effectively cancel the ancestor'srenderpriority
, since the ancestor would need to be rendered to render the descendant?
Wouldn't that also enable advertisers from just injecting HTML with
renderpriority="user-blocking"
to hog resources for their ads?
I've had some thoughts on a similar case here: https://github.com/WICG/display-locking/issues/200#issuecomment-919645611 I agree that upgrading the renderpriority to something higher in the subtree is problematic, since it would violate the ancestor render priority setting and cause more work than necessary (as you mention with the ads injecting high priority content). I believe there is no such issues if we keep the priority at the minimum of ancestor and nested element (i.e. if one of them is background, then the content in the inner element is updated with background priority). We are also considering not updating nested renderpriority things at all (ie treat them as renderpriority=never), which would simplify reasoning about this and allow us to have improvements in the future.
I would also have liked a discussion on what kind of performance gain would this enable, for a sufficiently complex DOM (e.g. the HTML spec). Are we increasing the complexity of the web platform to save some nanoseconds or is it a more significant gain?
I can add a section to the explainer to try and foster such a discussion. Just from dealing with content-visibility content, I can say that it saves anywhere on the order from milliseconds to seconds of load time. The way this is set up though is that the work is deferred until it is needed. With appropriately chunked content, content-visibility: auto
would naturally do this as the user scrolls, updating small pieces at a time as they enter the viewport. In the Single-Page App example that I alluded to, however, this means that whatever work you may save will still need to happen when the content is displayed to the user (and it would happen synchronously).
With this proposed feature, the developer can set renderpriority=background
on the element which will ultimately be presented to the user. This will allow the user-agent to start doing work in that subtree without displaying the content, but preparing things like style and layout values. When the content is ultimately presented, the work that was initially deferred would have already been completed, so the content is displayed faster. So the savings here largely depend on the complexity of the content displayed and the amount of time the user-agent had to update this with background priority.
How would an author use
renderpriority
to enable this use case? What value would they use? Are they supposed to change the value before navigation?
The developer would display the content (i.e. removing content-visibility: hidden
). Changing the renderpriority
value is something that they can do optionally as well, but I don't think it's a necessity to get the performance.
Comment by @LeaVerou Oct 13, 2021 (See Github)
Thank you for the explanation. Saving milliseconds to several seconds certainly sounds worthwhile to me.
I agree that upgrading the renderpriority to something higher in the subtree is problematic, since it would violate the ancestor render priority setting and cause more work than necessary (as you mention with the ads injecting high priority content). I believe there is no such issues if we keep the priority at the minimum of ancestor and nested element (i.e. if one of them is background, then the content in the inner element is updated with background priority). We are also considering not updating nested renderpriority things at all (ie treat them as renderpriority=never), which would simplify reasoning about this and allow us to have improvements in the future.
Given that the default renderpriority is user-visible
, wouldn't that effectively render user-blocking
impossible to use, unless you're willing to set it on the root, defeating its purpose?
Comment by @vmpstr Oct 13, 2021 (See Github)
Given that the default renderpriority is
user-visible
, wouldn't that effectively renderuser-blocking
impossible to use, unless you're willing to set it on the root, defeating its purpose?
Hmm, the default value is auto
which allows the user-agent to select "whatever is appropriate". You're right that we need to be careful not to set a lower default (I'll update the explainer to call this out). Currently though, we're only proposing that this attribute has an effect only if rendering of the contents of that element would be skipped by the user-agent. From the explainer,
If the User Agent does not optimize rendering of elements, by skipping work, then the attribute has no effect.
The question is, of course, if it has no effect on the element, does it still affect the nested renderattribute
settings. I don't think it should, but that's not (yet) clear in the explainer.
Discussed
Dec 1, 2021 (See Github)
Ken: part of the display locking effort...
Ken: they said they'd update explainer but so fare not...
Dan: leaves comment
Comment by @torgo Dec 14, 2021 (See Github)
Hi @vmpstr - we're just reviewing progress on this today and it looks like so far the explainer hasn't been updated. Do you you have any additional status you can share?
Comment by @vmpstr Dec 18, 2021 (See Github)
Hey, I apologize for the delay. I've just updated the explainer as a result of the discussions that we had on this issue.
Thank you!
Discussed
Jun 1, 2022 (See Github)
Hi @vmpstr,
@cynthia and I discussed this again today in a breakout today. On attribute vs CSS property we definitely think this is more suitable as a CSS property. This way it is easier to use it for creating defaults, including in Web components, and also given that it interacts with other CSS properties.
We are still not sure about certain details of the proposed algorithm, including my question from above about nesting higher priority elements inside lower priority elements.
We would like to see some examples of actually using the feature to target the user needs you are targeting. Are all these values necessary to address these use cases?
Comment by @LeaVerou Jun 21, 2022 (See Github)
Hi @vmpstr,
@cynthia and I discussed this again today in a breakout today. On attribute vs CSS property we definitely think this is more suitable as a CSS property. This way it is easier to use it for creating defaults, including in Web components, and also given that it interacts with other CSS properties.
We are still not sure about certain details of the proposed algorithm, including my question from above about nesting higher priority elements inside lower priority elements.
We would like to see some examples of actually using the feature to target the user needs you are targeting. Are all these values necessary to address these use cases?
Comment by @vmpstr Jun 28, 2022 (See Github)
Thank you for your feedback and questions!
On attribute vs CSS property we definitely think this is more suitable as a CSS property. This way it is easier to use it for creating defaults, including in Web components, and also given that it interacts with other CSS properties.
That makes sense, thanks.
We are still not sure about certain details of the proposed algorithm, including my question from above about nesting higher priority elements inside lower priority elements.
The intent is to have this property be treated as a maximum rendering priority for itself and its descendants. This would mean that higher priority descendants would still be limited by the lower priority ancestors. In other words, a parent with a background priority will cause all of its children to update with at most a background priority, even if one of its children is a user-blocking priority.
We would like to see some examples of actually using the feature to target the user needs you are targeting. Are all these values necessary to address these use cases?
- user-blocking - this is currently the behavior for most (all?) visible content: updates always happen synchronously even if that blocks other work
- user-visible - this priority isn't really required (the priorities were largely inspired by the task scheduling api)
- background - this is the most interesting priority to us, since that would allow developers to update
content-visibility: hidden
subtrees without blocking other important work. - never - this is currently the behavior for
content-visibility: hidden
subtrees, since the rendering in those subtrees is not updated. - auto - this seems like a nice default for the UA to select another priority. For example, UA can select "user-blocking" for visible content and "never" for content with
content-visibility: hidden
subtrees.
I don't have any working examples since we don't have a working prototype of this feature, but I can work to construct hypothetical examples where this would be useful.
Thanks again!
Discussed
Aug 1, 2022 (See Github)
closed on feedback from chris H. at Google
marked as "withdrawn"
Comment by @torgo Aug 23, 2022 (See Github)
closing for now based on @chrishtr - can be re-opened when appropriate
OpenedSep 16, 2021
Hello TAG!
I'm requesting a TAG review of renderPriority element attribute.
The renderPriority attribute is an HTML attribute that informs the User Agent to keep the element's rendering state updated with a specified priority. This is used on elements whose rendering state would not otherwise be kept up-to-date.
Further details:
We'd prefer the TAG provide feedback as (please delete all but the desired option):
💬 leave review feedback as a comment in this issue and @-notify @vmpstr