Skip to content

Commit ec95c92

Browse files
authored
[css-animationworklet] Move threading model out of spec and into README (w3c#904)
The Animation Worklet does not require or depend on the worklet running in a parallel execution context. In another word, it is valid and reasonable to run Animation Worklet on the main rendering thread. Similar to other Houdini primitives, the worklet is allowed to run on a different thread. This is an implementation detail that engine can take advantage of to improve animation smoothness. Given that threading model is an implementation detail, I move most of that discussion to the Explainer. The only aspect of that is relevant to the specification is "async" nature of worklet animation timing model (which enables the parallel execution mode). This is already discussed in "Worklet Animation timing model" and thus I moved the discussion of valid main thread sync opportunities for worklets to be part of that section.
1 parent 4b03d10 commit ec95c92

File tree

2 files changed

+50
-43
lines changed

2 files changed

+50
-43
lines changed

css-animationworklet/Overview.bs

+11-43
Original file line numberDiff line numberDiff line change
@@ -127,49 +127,6 @@ interface from the Web Animations specification on the main javascript execution
127127
they can be controlled and inspected from main thread using the same Web Animation APIs.
128128

129129

130-
Threading Model {#threading-model}
131-
==================================
132-
<em>This section is not normative.</em>
133-
134-
<a>Animation Worklet</a> is designed to be thread-agnostic. Rendering engines may create one or more
135-
parallel worklet execution contexts separate from the main javascript execution context, e.g., on
136-
their own dedicated threads. Rendering engines may then choose to assign Animation Worklet
137-
animations to run in such contexts. Doing so allows Animation Worklet animations to avoid being
138-
impacted by main thread jank.
139-
140-
Rendering engines may wish to make a best-effort attempt to execute animate callbacks synchronously
141-
with visual frame production to ensure smooth animation. However it is legal for rendering engines
142-
to produce visual frames without blocking to receive animation updates from a worklet (i.e., letting
143-
the effects slip behind). For example, this could occur when the <a>animate function</a> callback is
144-
unable to complete before the frame deadline.
145-
146-
We believe that scripted animations which are run in a parallel execution environment and which
147-
limit themselves to animating properties which do not require the user agent to consult main thread
148-
will have a much better chance of meeting the strict frame budgets required for smooth playback.
149-
150-
If a Worklet Animation animation is executing in a parallel worklet execution context, the last
151-
known state of its animation effects should be periodically synced back to the main javascript
152-
execution context. The synchronization of <a>effect values</a> from the parallel worklet execution
153-
context to the main javascript execution context <em>must</em> occur before <a>running the animation
154-
frame callbacks</a> as part of the document lifecycle. Note that due to the asynchronous nature of
155-
this animation model a script running in the main javascript execution context may see a stale value
156-
when reading a <a>target property</a> that is being animated in a Worklet Animation, compared to the
157-
value currently being used to produce the visual frame that is visible to the user. This is similar
158-
to the effect of asynchronous scrolling when reading scroll offsets in the main javascript execution
159-
context.
160-
161-
162-
<figure>
163-
<img src="img/AnimationWorklet-threading-model.svg" width="600"
164-
alt="Overview of the animation worklet threading model.">
165-
<figcaption>
166-
Overview of the animation worklet threading model. <br>
167-
168-
A simplified visualization of how animators running in a parallel execution environment can sync
169-
their update to main thread while remaining in sync with visual frame production.
170-
</figcaption>
171-
</figure>
172-
173130
Animation Worklet {#animation-worklet-desc}
174131
==============================
175132
<dfn>Animation Worklet</dfn> is a {{Worklet}} responsible for all classes related to custom
@@ -685,6 +642,17 @@ Here are a few implications of the above semantics:
685642
may return stale information, in the case where the <a>animator instance</a> is running in a
686643
parallel execution context.
687644

645+
If a Worklet Animation animation is executing in a parallel worklet execution context, the last
646+
known state of its animation effects should be periodically synced back to the main javascript
647+
execution context. The synchronization of <a>effect values</a> from the parallel worklet execution
648+
context to the main javascript execution context <em>must</em> occur before <a>running the animation
649+
frame callbacks</a> as part of the document lifecycle. Note that due to the asynchronous nature of
650+
this animation model a script running in the main javascript execution context may see a stale value
651+
when reading a <a>target property</a> that is being animated by a Worklet Animation, compared to the
652+
value currently being used to produce the visual frame that is visible to the user. This is similar
653+
to the effect of asynchronous scrolling when reading scroll offsets in the main javascript execution
654+
context.
655+
688656
Issue(811): Come with appropriate mechanism's for <a>animator instance</a> to get notified when its
689657
animation currentTime is changing e.g., via reverse(), finish() or playbackRate change. So that
690658
it can react appropriately.

css-animationworklet/README.md

+39
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,45 @@ registerAnimator('animation-with-local-state', class FoorAnimator extends Statef
545545
});
546546
```
547547

548+
549+
## Threading Model
550+
551+
Animation Worklet is designed to be thread-agnostic. Rendering engines may create one or more
552+
parallel worklet execution contexts separate from the main javascript execution context, e.g., on
553+
their own dedicated threads. Rendering engines may then choose to assign Animation Worklet
554+
animations to run in such contexts. Doing so allows Animation Worklet animations to avoid being
555+
impacted by main thread jank.
556+
557+
Rendering engines may wish to make a best-effort attempt to execute animate callbacks synchronously
558+
with visual frame production to ensure smooth animation. However it is legal for rendering engines
559+
to produce visual frames without blocking to receive animation updates from a worklet (i.e., letting
560+
the effects slip behind). For example, this could occur when the animate function callback is
561+
unable to complete before the frame deadline.
562+
563+
We believe that scripted animations which are run in a parallel execution environment and which
564+
limit themselves to animating properties which do not require the user agent to consult main thread
565+
will have a much better chance of meeting the strict frame budgets required for smooth playback.
566+
567+
568+
Note that due to the asynchronous nature of this animation model a script running in the main
569+
javascript execution context may see a stale value when reading a target property that is
570+
being animated in a Worklet Animation, compared to the value currently being used to produce the
571+
visual frame that is visible to the user. This is similar to the effect of asynchronous scrolling
572+
when reading scroll offsets in the main javascript execution context.
573+
574+
575+
<figure>
576+
<img src="img/AnimationWorklet-threading-model.svg" width="600"
577+
alt="Overview of the animation worklet threading model.">
578+
<figcaption>
579+
Overview of the animation worklet threading model. <br>
580+
581+
A simplified visualization of how animators running in a parallel execution environment can sync
582+
their update to main thread while remaining in sync with visual frame production.
583+
</figcaption>
584+
</figure>
585+
586+
548587
# Related Concepts
549588

550589
The following concepts are not part of Animation Worklet specification but Animation Worklet is

0 commit comments

Comments
 (0)