-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow speculative evaluation #439
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments based on an IRC conversation with @asajeffrey.
worklets/Overview.bs
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I tried rephrasing it.
css-paint-api/Overview.bs
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
1. Let |paintFunction| be the <<paint()>> function on the |box| which the user agent wants to | ||
draw. | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll file an issue for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Submitted another commit with some edits.
css-paint-api/Overview.bs
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
1. Let |paintFunction| be the <<paint()>> function on the |box| which the user agent wants to | ||
draw. | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
worklets/Overview.bs
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I tried rephrasing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
1. Let |paintFunction| be the <<paint()>> function on the |box| which the user agent wants to | ||
draw. | ||
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a separate section which allows for the caching inside "invoke a paint callback", see step 10.
worklets/Overview.bs
Outdated
Speculative Evaluation {#speculative-evaluation} | ||
------------------------------------------------ | ||
|
||
Some specifications which use worklets ([[css-paint-api-1]]) may |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please reflow to 100 colwidth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
css-paint-api/Overview.bs
Outdated
@@ -450,6 +451,16 @@ Note: In a future version of the spec, the author could have the ability to spec | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please reflow to 100 colwidth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed fill column.
css-paint-api/Overview.bs
Outdated
@@ -450,6 +451,16 @@ Note: In a future version of the spec, the author could have the ability to spec | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
worklets/Overview.bs
Outdated
Speculative Evaluation {#speculative-evaluation} | ||
------------------------------------------------ | ||
|
||
Some specifications which use worklets ([[css-paint-api-1]]) may |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
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.