W3C home > Mailing lists > Public > whatwg@whatwg.org > December 2011

[whatwg] A better animation API

From: Boris Zbarsky <bzbarsky@MIT.EDU>
Date: Sat, 10 Dec 2011 03:13:57 -0500
Message-ID: <4EE314C5.6040801@mit.edu>
On 12/10/11 3:11 AM, Boris Zbarsky wrote:
> On 12/10/11 2:55 AM, Robert Eisele wrote:
>> It's certainly also more difficult to implement but asking for every
>> frame
>> to continue has also the disadvantage of beeing as slow as setting up
>> a new
>> timeout for every frame. That's why setInterval surpass setTimeout's
>> performance (okay, at least it should).
> In theory, yes.

One other note.

The principal practical difference between setInterval and setTimeout 
(other than all the pages that setInterval something and then forget to 
cancel it) is their handling of delays in firing times.  With 
setInterval you can get a more uniformly firing timer, because if one 
firing gets delayed the next one might compensate.  With setTimeout the 
only way to get that behavior is to manually compensate by comparing the 
actual firing time to the desired one and adjusting the argument to the 
next setTimeout call accordingly.

With requestAnimationFrame, of course, the firing time thing is a 
non-issue, because you're not scheduling a callback for a particular 
time in the first place.

Received on Saturday, 10 December 2011 00:13:57 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:38 UTC