Skip to content

Allow speculative evaluation#439

Merged
bfgeek merged 5 commits into
w3c:masterfrom
asajeffrey:speculative-evaluation
Nov 9, 2017
Merged

Allow speculative evaluation#439
bfgeek merged 5 commits into
w3c:masterfrom
asajeffrey:speculative-evaluation

Conversation

@asajeffrey
Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread 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.
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread css-paint-api/Overview.bs

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

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

Comment thread css-paint-api/Overview.bs

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread css-paint-api/Overview.bs

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

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

Comment thread css-paint-api/Overview.bs

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
Copy Markdown
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.

Comment thread 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.
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread css-paint-api/Overview.bs

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
Copy Markdown
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.

Comment thread worklets/Overview.bs Outdated
Speculative Evaluation {#speculative-evaluation}
------------------------------------------------

Some specifications which use worklets ([[css-paint-api-1]]) may
Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Comment thread css-paint-api/Overview.bs Outdated
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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

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

Comment thread css-paint-api/Overview.bs Outdated
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Comment thread worklets/Overview.bs Outdated
Speculative Evaluation {#speculative-evaluation}
------------------------------------------------

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

Choose a reason for hiding this comment

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

Done.

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