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

Re: solving the CPU usage issue for non-visible pages

From: Robert O'Callahan <robert@ocallahan.org>
Date: Tue, 20 Oct 2009 10:51:53 +1300
Message-ID: <11e306600910191451h3bdb191ap3f408943dcc0ddbc@mail.gmail.com>
To: public-webapps@w3.org
I have a proposal for solving this here:
http://groups.google.com/group/mozilla.dev.platform/browse_thread/thread/527d0cedb9b0df7f/57625c94cdf493bf

The gist is very simple:
1) window.requestAnimationFrame(): Signals that an animation is in progress,
and requests that the browser schedule a repaint of the window for the next
animation frame, if the window is visible.
2) The browser fires a beforePaint event at the document root element
(bubbling to document and window) any time it repaints the window. This
event contains a 'displayTime' field containing a Javascript Date object
representing the time at which this frame is likely to become visible to the
user. Animation scripts should register an event handler that updates the
DOM/CSS state to show that point in the animation. If the animation has not
ended, the event handler should call window.requestAnimationFrame() again to
ensure another frame will be scheduled in a timely manner.

This gives the browser control over the frame rate, lets it suppress
animation in non-visible windows, lets multiple animations play in
synchrony, and should be easy to retrofit into code that's currently based
on setInterval. I think it can also work well with architectures that do
compositing in a dedicated thread or process.

Rob
-- 
"He was pierced for our transgressions, he was crushed for our iniquities;
the punishment that brought us peace was upon him, and by his wounds we are
healed. We all, like sheep, have gone astray, each of us has turned to his
own way; and the LORD has laid on him the iniquity of us all." [Isaiah
53:5-6]
Received on Monday, 19 October 2009 21:52:27 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:34 GMT