Skip to content

Commit 36f9c91

Browse files
Alan Jeffreybfgeek
Alan Jeffrey
authored andcommitted
Allow speculative evaluation (w3c#439)
Added text allowing speculative evaluation. Fixes w3c#406.
1 parent 0b0acac commit 36f9c91

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

css-paint-api/Overview.bs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ Note: The user agent can optionally defer drawing images which are <a>paint-inva
451451
</div>
452452

453453
The <a>draw a paint image</a> function is invoked by the user agent during the <a>object size
454-
negotiation</a> algorithm which is responsible for rendering an <<image>>.
454+
negotiation</a> algorithm which is responsible for rendering an <<image>>,
455+
with |concreteObjectSize| set to the <a>concrete object size</a> of the <a>box</a>.
455456

456457
For the purposes of the <a>object size negotiation</a> algorithm, the paint image has no
457458
<a>intrinsic dimensions</a>.
@@ -467,6 +468,15 @@ the <a>concrete object size</a> given by the user agent.
467468
Note: See [[css-images-3#object-sizing-examples]] for examples on how the <a>concrete object
468469
size</a> is calculated.
469470

471+
The <a>draw a paint image</a> function may be speculatively invoked by the user agent at any point,
472+
with any |concreteObjectSize|. The resulting image is not displayed.
473+
474+
Note: User agents may use any heuristic to speculate a possible future value for |concretObjectSize|,
475+
for example speculating that the size remains unchanged.
476+
477+
Note: Although the image is not displayed, it may still be cached, and subsequent invocations of
478+
<<paint()>> may use the cached image.
479+
470480
<pre class='idl'>
471481
[Exposed=PaintWorklet]
472482
interface PaintSize {
@@ -478,12 +488,12 @@ interface PaintSize {
478488
<div algorithm>
479489
When the user agent wants to <dfn>draw a paint image</dfn> of a <<paint()>> function for a |box|
480490
into its appropriate stacking level (as defined by the property the CSS property its associated
481-
with), given its |concreteObjectSize| (<a>concrete object size</a>) it <em>must</em> run the
482-
following steps:
491+
with), given |concreteObjectSize| it <em>must</em> run the following steps:
483492
1. Let |paintFunction| be the <<paint()>> function on the |box| which the user agent wants to
484493
draw.
485494

486-
2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a> the user agent
495+
2. If the <a>paint valid flag</a> for the |paintFunction| is <a>paint-valid</a>,
496+
and the previous invocation had the same |concreteObjectSize|, the user agent
487497
<em>may</em> use the drawn image from the previous invocation. If so it <em>may</em> abort
488498
all these steps and use the previously drawn image.
489499

worklets/Overview.bs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ The following techniques are used in order to encourage authors to write code in
123123

124124
- User agents can create and destroy {{WorkletGlobalScope}}s at any time for these specifications.
125125

126+
Speculative Evaluation {#speculative-evaluation}
127+
------------------------------------------------
128+
129+
Some specifications which use worklets ([[css-paint-api-1]]) may invoke methods on a class based on
130+
the state of the user agent. To increase the concurrency between threads, a user agent may invoke a
131+
method speculatively, based on potential future states.
132+
133+
In these specifications user agents might invoke methods on a class at any time, and with any
134+
arguments, not just ones corresponding to the current state of the user agent. The results of such
135+
speculative evaluations are not displayed immediately, but may be cached for use if the user agent
136+
state matches the speculated state. This may increase the concurrency between the user agent and
137+
worklet threads.
138+
139+
As a result of this, to prevent this compatibility risk between user agents, authors who register
140+
classes on the global scope using these APIs, should make their code stateless. That is, the only
141+
effect of invoking a method should be its result, not any side-effects such as updating mutable
142+
state.
143+
144+
The same techniques which encourage code idempotence also encourage authors to write stateless code.
145+
126146
Infrastructure {#infrastructure}
127147
================================
128148

0 commit comments

Comments
 (0)