Allow speculative evaluation#439
Conversation
tschneidereit
left a comment
There was a problem hiding this comment.
Some comments based on an IRC conversation with @asajeffrey.
| any time, and with any arguments, not just ones corresponding to | ||
| consistent states of the user agent. The results of such speculative | ||
| evaluations will be discarded, but may be cached for later use, thus | ||
| increasing the concurrency between the user agent and worklet threads. |
There was a problem hiding this comment.
I think this paragraph is slightly misleading in two ways:
- The methods won't be invoked with inconsistent state so much as with potential future state. The result will be used iff, when the time the invocation was done for has arrived, the actual state of the user agent matches what was passed in speculatively.
- The results aren't discarded; they're not used immediately, but saved and hopefully used once the time the invocation was done for has arrived.
There was a problem hiding this comment.
Good point, I tried rephrasing it.
|
|
||
| Note: Although the image is discarded, it may still be cached, so subsequent invocations | ||
| of <<paint()>> may use the cached image. | ||
|
|
There was a problem hiding this comment.
Do we need to be this general about which value the function might be invoked with and when? Being more explicit about when and why a user agent might do this might be useful:
"The draw a paint image function may be speculatively invoked by the user agent with an expected value for |concreteObjectSize|. Once the |concreteObjectSize| is known, the resulting image either used if the speculation succeeded or discarded if the speculation failed."
There was a problem hiding this comment.
I added text to the note: "Note: User agents may use whichever heuristics to speculate a possible future value for |concretObjectSize|, for example speculating that the size remains unchanged." I'm not sure that we want to say more about how to speculate in the normative text.
I replaced "discarded" by "not displayed", which is hopefully less confusing.
|
|
||
| 2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a> the user agent | ||
| 2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a>, | ||
| and the previous invocation had the same |concreteObjectSize|, the user agent |
There was a problem hiding this comment.
This implies that there can only ever be one speculative evaluation at a time. If we want to allow speculating multiple frames ahead, this should probably say something about checking for results of a speculative evaluation that match the input state.
There was a problem hiding this comment.
All the discussion of the paint valid flag is dubious, perhaps we should just delete it? It's very single-threaded. This is probably a separate issue though.
There was a problem hiding this comment.
There is a separate section which allows for the caching inside "invoke a paint callback", see step 10.
There was a problem hiding this comment.
@bfgeek yes, this is why I was thinking we could just remove all the stuff about the paint valid flag, since we're already allowing caching inside "invoke a paint callback". Shall I submit a separate PR for that?
There was a problem hiding this comment.
Yeah that sounds good, we still need to describe how the inputProperties invalidate that image on a box, but we can have that in prose vs. as an algorithm.
There was a problem hiding this comment.
OK, I'll file an issue for this.
asajeffrey
left a comment
There was a problem hiding this comment.
Submitted another commit with some edits.
|
|
||
| Note: Although the image is discarded, it may still be cached, so subsequent invocations | ||
| of <<paint()>> may use the cached image. | ||
|
|
There was a problem hiding this comment.
I added text to the note: "Note: User agents may use whichever heuristics to speculate a possible future value for |concretObjectSize|, for example speculating that the size remains unchanged." I'm not sure that we want to say more about how to speculate in the normative text.
I replaced "discarded" by "not displayed", which is hopefully less confusing.
|
|
||
| 2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a> the user agent | ||
| 2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a>, | ||
| and the previous invocation had the same |concreteObjectSize|, the user agent |
There was a problem hiding this comment.
All the discussion of the paint valid flag is dubious, perhaps we should just delete it? It's very single-threaded. This is probably a separate issue though.
| any time, and with any arguments, not just ones corresponding to | ||
| consistent states of the user agent. The results of such speculative | ||
| evaluations will be discarded, but may be cached for later use, thus | ||
| increasing the concurrency between the user agent and worklet threads. |
There was a problem hiding this comment.
Good point, I tried rephrasing it.
tschneidereit
left a comment
There was a problem hiding this comment.
Thanks, this looks great to me.
|
|
||
| 2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a> the user agent | ||
| 2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a>, | ||
| and the previous invocation had the same |concreteObjectSize|, the user agent |
There was a problem hiding this comment.
There is a separate section which allows for the caching inside "invoke a paint callback", see step 10.
| Speculative Evaluation {#speculative-evaluation} | ||
| ------------------------------------------------ | ||
|
|
||
| Some specifications which use worklets ([[css-paint-api-1]]) may |
There was a problem hiding this comment.
please reflow to 100 colwidth.
| The {{PaintSize}} object represents the size of the image that the author should draw. This is | ||
| the <a>concrete object size</a> given by the user agent. | ||
|
|
||
| The <a>draw a paint image</a> function may be speculatively invoked by |
There was a problem hiding this comment.
please reflow to 100 colwidth.
| The {{PaintSize}} object represents the size of the image that the author should draw. This is | ||
| the <a>concrete object size</a> given by the user agent. | ||
|
|
||
| The <a>draw a paint image</a> function may be speculatively invoked by |
| Speculative Evaluation {#speculative-evaluation} | ||
| ------------------------------------------------ | ||
|
|
||
| Some specifications which use worklets ([[css-paint-api-1]]) may |
|
Thanks! |
Currently, user agents can only invoke worklets with consistent snapshots of the state. This PR allows user agents to invoke worklet scripts with inconsistent state, as long as they discard the result.
The particular instance of this is paint worklets, since the CSS style values are known before the concrete size, so in Servo we speculate that the size hasn't changed (servo/servo#17810).
Fixes #406.