Bug 67171

Summary: requestAnimationFrame doesn't throttle on Mac
Product: WebKit Reporter: Chris Marrin <cmarrin>
Component: WebKit Misc.Assignee: Chris Marrin <cmarrin>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, dongseong.hwang, jamesr, kevin.cs.oh, simon.fraser
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Mac   
OS: OS X 10.7   
URL: https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/sdk/demos/webkit/SpiritBox.html
Bug Depends on:    
Bug Blocks: 64591    
Attachments:
Description Flags
Patch
none
Patch simon.fraser: review+

Chris Marrin
Reported 2011-08-29 17:28:17 PDT
The demos at the WebGL repository run at hundreds of FPS on Mac. They use requestAnimationFrame, which is not throttled and should be.
Attachments
Patch (21.37 KB, patch)
2011-09-09 17:32 PDT, Chris Marrin
no flags
Patch (21.35 KB, patch)
2011-09-09 18:12 PDT, Chris Marrin
simon.fraser: review+
Simon Fraser (smfr)
Comment 1 2011-08-31 11:42:36 PDT
Dean Jackson
Comment 2 2011-08-31 13:52:39 PDT
We should also throttle to 1 fps or below in inactive tabs.
James Robinson
Comment 3 2011-09-01 11:36:16 PDT
(In reply to comment #2) > We should also throttle to 1 fps or below in inactive tabs. Please read the discussion on public-web-perf@w3.org about this. Currently in Chrome we throttle inactive tabs completely, but Firefox fires at a very low rate. We've considered moving to a 0.1Hz throttle for inactive tabs, but haven't done this yet.
Chris Marrin
Comment 4 2011-09-09 17:32:59 PDT
Simon Fraser (smfr)
Comment 5 2011-09-09 17:43:58 PDT
Comment on attachment 106946 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=106946&action=review > Source/WebCore/dom/ScriptedAnimationController.cpp:40 > +#define MaximumAnimationInterval 0.015 This is a minimum interval, not a maximum > Source/WebCore/dom/ScriptedAnimationController.cpp:142 > + double scheduleTime = MaximumAnimationInterval - (currentTime() - m_timeSinceLastAnimationFrame); scheduleTime is not an absolute time, it's an interval. The name should reflect this. Call it 'delay' maybe. Is currentTime() the right thing to use? I thought we had a "time for all the current animations" value. I find this hard to read. Is m_timeSinceLastAnimationFrame just there for clamping? If so, what's MaximumAnimationInterval for? m_timeSinceLastAnimationFrame is also poorly named. It's not an interval, it's an absolute time. > Source/WebCore/dom/ScriptedAnimationController.cpp:155 > + m_timeSinceLastAnimationFrame = currentTime(); Is currentTime() the right thing to use again?
Chris Marrin
Comment 6 2011-09-09 18:10:24 PDT
(In reply to comment #5) > (From update of attachment 106946 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=106946&action=review > > > Source/WebCore/dom/ScriptedAnimationController.cpp:40 > > +#define MaximumAnimationInterval 0.015 > > This is a minimum interval, not a maximum > > > Source/WebCore/dom/ScriptedAnimationController.cpp:142 > > + double scheduleTime = MaximumAnimationInterval - (currentTime() - m_timeSinceLastAnimationFrame); > > scheduleTime is not an absolute time, it's an interval. The name should reflect this. Call it 'delay' maybe. > > Is currentTime() the right thing to use? I thought we had a "time for all the current animations" value. > > I find this hard to read. Is m_timeSinceLastAnimationFrame just there for clamping? If so, what's MaximumAnimationInterval for? > > m_timeSinceLastAnimationFrame is also poorly named. It's not an interval, it's an absolute time. Everything above has been changed... > > > Source/WebCore/dom/ScriptedAnimationController.cpp:155 > > + m_timeSinceLastAnimationFrame = currentTime(); > > Is currentTime() the right thing to use again? This is what we were using with the old implementation, so I think we should keep it, at least until we get the CSS Animations to fire off rAF.
Chris Marrin
Comment 7 2011-09-09 18:12:24 PDT
Simon Fraser (smfr)
Comment 8 2011-09-09 18:42:44 PDT
Comment on attachment 106949 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=106949&action=review > Source/WebCore/dom/ScriptedAnimationController.cpp:145 > + double scheduleDelay = max(MinimumAnimationInterval - (currentTime() - m_lastAnimationFrameTime), 0.0); You can use max<double> to avoid the "0.0". > Source/WebCore/dom/ScriptedAnimationController.h:76 > + Timer<ScriptedAnimationController> m_animationTimer;\ I don't think this compiled.
Chris Marrin
Comment 9 2011-09-10 06:58:12 PDT
(In reply to comment #8) > (From update of attachment 106949 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=106949&action=review > > > Source/WebCore/dom/ScriptedAnimationController.cpp:145 > > + double scheduleDelay = max(MinimumAnimationInterval - (currentTime() - m_lastAnimationFrameTime), 0.0); Done > > You can use max<double> to avoid the "0.0". > > > Source/WebCore/dom/ScriptedAnimationController.h:76 > > + Timer<ScriptedAnimationController> m_animationTimer;\ > > I don't think this compiled. Yeah, I don't know where that came from. Gone now.
Chris Marrin
Comment 10 2011-09-10 07:20:07 PDT
James Robinson
Comment 11 2011-09-12 13:38:19 PDT
Is there any particular reason why you picked 15ms instead of 16ms (or possibly a repeating pattern of 16,17,17,16,17,17,... to try to match up with 60Hz displays)?
Chris Marrin
Comment 12 2011-09-12 14:23:55 PDT
(In reply to comment #11) > Is there any particular reason why you picked 15ms instead of 16ms (or possibly a repeating pattern of 16,17,17,16,17,17,... to try to match up with 60Hz displays)? Well, there's no "matching up" going on. So the best we could do it tune the number to 60hz so we don't, on average, render more times that is being displayed. The problem with setting the number to 16.67ms is that in many cases that will cause you to miss a 60Hz rate due to the overhead of firing the timer and servicing the event. So 15ms mostly avoid renders that will never be seen, but will prevent the overhead from causing a framerate miss.
Dongseong Hwang
Comment 13 2012-01-03 17:28:58 PST
I disagree this patch. I think each platform (ex> webview) should throttle FPS, not WebCore. I have the counter example. If 2d canvas has heavy animation, it is possible that requestAnimationFrame is called several times per one update of WebView.
Note You need to log in before you can comment on or make changes to this bug.