-
Notifications
You must be signed in to change notification settings - Fork 707
[web-animations-2] controlling animation frame rate #7196
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
Comments
Thanks for this. I read through the explainer but I was bit unsure about exactly where in the rendering pipeline the change in frame rate is realized. Particularly this note:
I think this applies equally to things like resolving the My understanding of the proposal is that we are suggesting modifying the update animations and send events procedure to partition the set of animations into separate buckets such that only a subset of animations might be updated each time? Is that right? If so, I think it would require a shift in the way time values flow down the timing hierarchy. Potentially some animations are taking their current time value directly from the timeline whilst others are using a cached value? If so, perhaps the values returned by the API could look inconsistent? Or would we always update all animations at the local maximum frame rate for a given timeline (i.e. the maximum frame rate for all animations attached to it) but only dirty style for those that need an update in this particular frame? That way at least all the values seems consistent from the API? Incidentally, if we made the timeline the point where the frame rate was controlled I think we would avoid a lot of these issues. It's more clumsy, since you'd need to create a new |
Oh, and do we need to give any thought to how we might discourage content from slapping |
Nice, this is a really interesting addition, and possibly a good way to strike a balance between smooth animations and battery drain (e.g. by ads). I'm trying to wrap my head around
let lastTime = document.timeline.currentTime;
const animation = new Animation({ frameRate: 'high' });
animation.effect = new CustomEffect(() => {
// figure out how much time has passed
const time = document.timeline.currentTime;
const deltaTime = time - lastTime;
lastTime = time;
// Update game objects
tick(deltaTime);
// Render scene with WebGL
render();
}, Infinity);
animation.play();
Thanks in advance and sorry for the wall of questions 😅 |
I'd love to know too! A few of our animations are driven by gestures, currently inside rAFs. We're wondering what the future solutions would be so that we can leverage ProMotion, since Safari's capping rAF at 60fps |
I agree, I think the timeline is the right place for the framerate control. It also implies all animations on the same timeline would be aligned to the same ticks (which is presumably what you would want in most cases), and answers a bunch of other questions.
I think we could make the mapping to CSS work. E.g. this would probably be specifying a different I also think it would be nice if you could modify the default document timeline to tick at a different rate if you want to as a site set the rate of your animations by default. |
Any single page is usually made up of different teams work. It isn't hard to imagine those teams competing with each other for higher frame rates. I also wonder if this is giving developer control of something the browser should handle for them. What if the developer specifies something that makes the user experience worse. What would the browser do in that case? |
Re @stubbornella, on non-webkit browsers this is what we have today: every animation tries to be the full frame rate (on webkit, all main thread animations are 60Hz). So this API is letting developers tell the browsers which animations are actually important so the browser has more information to include in its scheduling decisions. Without this, I'm not sure how the browser would be able to tell whether a particular animation was more or less important than another. |
@flackr the linked document in the OP suggests these use cases for low frame rate animations:
It would be trivial to automatically bump at least these last two into a lower frame rate. IMO rather than exposing an API for this, which so far is pretty poorly defined, it would be better to spec out values/easings that should run at a lower frame rate via CSS/WAAPI and limit those to 60fps. Edit: To elaborate on "so far poorly defined".
So on a 60fps display |
Steps is in fact already optimizable, and there are some optimizations in place in blink for this. A few challenges we ran into working with developers to lower the framerate of some animations using steps:
I do worry about degrading experiences automatically (e.g. the opacity / filter cases) without some developer control |
@mattgperry I agree that the named rates are poorly defined and pushed back on this in other forums. I'm not arguing for this exact proposal, just arguing the case for why having an animation timeline tick rate would be helpful, especially if you could modify the default document timeline rate, a developer could easily:
|
I can see the argument for opting all animations on the page to a lower rate but I think it would be incomplete without a way of excepting some animations/JS callback loops ( In terms of the proposed names, it would make more sense to be able to define a Or, given that there will be a handful of framerates that people will commonly want to define, also allow some names with explicit, unambiguous mapping:
|
I was thinking something like this: const highPerformance = new DocumentTimeline({minInterval: 0}); // use this timeline for max frame rate.
document.timeline.minInterval = 1000 / 30; // Run default effects at 30fps. Note: I've used interval between ticks as it is similar to setInterval and allows expressing unlimited / maximum easily - with 0 - rather than needing to specify some high framerate. I'm not sure if you change the default document timeline rate though how we would express whether we want to limit or not limit inputs so maybe it needs to be more nuanced. |
Apple has started working on an experimental feature (off by default in Safari Technology Preview) to control the animation frame rate of animations, with an explainer detailing an initial proposal.
To summarize, we would like to allow authors to specify a frame rate for animations such that it would be possible to identify the relative impact of animations, some preferring to run at lower frame rates – and thus allowing to optimize the cadence at which the page is rendered – and some at higher frame rates for maximum visual impact.
Authors would specify a frame rate, either via a keyword (
auto
,low
,high
,highest
) or using an explicit value.This proposal would tie in nicely with the notion of a
CustomEffect
(see #6861) such that scripted animations could easily adjust their frame rate without changing their logic.Cc @smfr
The text was updated successfully, but these errors were encountered: