W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2010

Re: requestAnimationFrame

From: Robert O'Callahan <robert@ocallahan.org>
Date: Tue, 16 Nov 2010 15:55:10 +1300
Message-ID: <AANLkTim1CTaQXwa8qshY5MnWW0UkedfTE2VEJqKUewWC@mail.gmail.com>
To: "Gregg Tavares (wrk)" <gman@google.com>
Cc: "public-webapps@w3.org" <public-webapps@w3.org>
On Tue, Nov 16, 2010 at 1:26 PM, Gregg Tavares (wrk) <gman@google.com>wrote:

> On Mon, Nov 15, 2010 at 3:58 PM, Robert O'Callahan <robert@ocallahan.org>wrote:
>> If you really want to animate in 10Hz steps, then I suggest you do
>> something like
>> var start = window.animationTime;
>> var rate = 10; // Hz
>> var duration = 10; // s
>> var lastFrameNumber;
>> function animate() {
>>   var elapsed = window.animationTime - start;
>>   if (elapsed < duration) {
>>     window.requestAnimationFrame(animate);
>>   }
>>   var frameNumber = Math.round(elapsed/(1000/rate));
>>   if (frameNumber == lastFrameNumber)
>>     return;
>>   lastFrameNumber = frameNumber;
>>   // ... update the display based on frameNumber ...
>> }
>> window.requestAnimationFrame(animate);
> That seems quite a bit more complicated than
>    setInterval(myRenderFunction, 100);
> Which is what you'd do today.

Sure, but a) it's easily implemented once as a ten-line function in a
library and b) it's a lot more useful than setInterval ... for example it
automatically skips frames as necessary.

There is plenty of flash content that has a lower than 60hz (or fast as
> possible) refresh rate. When something is instead implementing in HTML5
> instead of Flash what should they do to get the similar results? Checking
> cnn.com, time.com, arstechnica.com, wired.com and msnbc.com I found that 7
> ads were set to run at 18hz, 3 were set to run at 24hz, 2 were set to run at
> 30hz. I used SWF Info<https://addons.mozilla.org/en-US/firefox/addon/45361/>to check the fps setting. I have no idea why they don't choose "run as fast
> as possible." I could be laziness, it could be that it makes the pages too
> slow and unresponsive to set them to "as fast as possible", it could be that
> rendering 3 times more then necessary, 60hz vs 18hz would eat battery
> life, it could be an artistic choice, it could be just that flash makes you
> pick one vs defaulting to "fast as possible".

OK, it would be useful to know the relative frequency of those reasons.

Reasons of the form "makes the page too slow/eats too much battery" actually
do not make compelling use-cases. Author-chosen frame rates for performance
reasons are generally going to be wrong because the author doesn't know the
capabilities of the client. Instead, the browser should be choosing the
frame rate(s). IMHO the only feature we *might* want to add here is to allow
authors to specify relative priorities somehow.

"Now the Bereans were of more noble character than the Thessalonians, for
they received the message with great eagerness and examined the Scriptures
every day to see if what Paul said was true." [Acts 17:11]
Received on Tuesday, 16 November 2010 02:55:39 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:28 UTC