Skip to content
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

Merged
merged 5 commits into from
Nov 9, 2017
Merged

Conversation

asajeffrey
Copy link

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.

Copy link
Member

@tschneidereit tschneidereit left a 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.

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.
Copy link
Member

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.

Copy link
Author

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.


Note: Although the image is discarded, it may still be cached, so subsequent invocations
of <<paint()>> may use the cached image.

Copy link
Member

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."

Copy link
Author

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
Copy link
Member

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

@asajeffrey asajeffrey left a 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.


Note: Although the image is discarded, it may still be cached, so subsequent invocations
of <<paint()>> may use the cached image.

Copy link
Author

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
Copy link
Author

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.

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.
Copy link
Author

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.

Copy link
Member

@tschneidereit tschneidereit left a 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.

Copy link
Contributor

@bfgeek bfgeek left a 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
Copy link
Contributor

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.

Speculative Evaluation {#speculative-evaluation}
------------------------------------------------

Some specifications which use worklets ([[css-paint-api-1]]) may
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -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
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Author

@asajeffrey asajeffrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed fill column.

@@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Speculative Evaluation {#speculative-evaluation}
------------------------------------------------

Some specifications which use worklets ([[css-paint-api-1]]) may
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@bfgeek bfgeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@bfgeek bfgeek merged commit 36f9c91 into w3c:master Nov 9, 2017
@asajeffrey
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants