Bug 94719 - [Chromium] Unnecessary delay when starting to update resources with an inactive vsync timer.
Summary: [Chromium] Unnecessary delay when starting to update resources with an inacti...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P1 Critical
Assignee: David Reveman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-22 09:29 PDT by David Reveman
Modified: 2012-08-23 08:42 PDT (History)
7 users (show)

See Also:


Attachments
Patch (1.76 KB, patch)
2012-08-22 09:32 PDT, David Reveman
no flags Details | Formatted Diff | Diff
Patch (2.52 KB, patch)
2012-08-22 13:10 PDT, David Reveman
no flags Details | Formatted Diff | Diff
Patch (7.46 KB, patch)
2012-08-22 14:59 PDT, David Reveman
no flags Details | Formatted Diff | Diff
Patch (8.98 KB, patch)
2012-08-22 15:29 PDT, David Reveman
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Reveman 2012-08-22 09:29:32 PDT
We're calling CCDelayBasedTimeSource::nextTickTime() before the timer is activated and nextTickTime() then returns 0.
Comment 1 David Reveman 2012-08-22 09:32:46 PDT
Created attachment 159953 [details]
Patch

Simple fix. It might be more appropriate to re-factor CCScheduler to not call nextTickTime() on an inactive timer
Comment 2 Nat Duca 2012-08-22 10:03:09 PDT
Comment on attachment 159953 [details]
Patch

I like this. @brianderson?
Comment 3 David Reveman 2012-08-22 11:52:56 PDT
Increasing priority as this bug is causing animations driven of requestAnimationFrame to run at half of the nominal frame rate.
Comment 4 James Robinson 2012-08-22 12:18:31 PDT
This seems OK.  The complexity here is getting scary.  Is there any way we could have caught this regression more directly?

I think Brian should take a look but we should land ASAP to get coverage back on the perf bots downstream.
Comment 5 Brian Anderson 2012-08-22 12:44:01 PDT
I'm fine with getting this in, but would like to change it eventually, since it's lying about what the next tick time actually is.  Also, the behavior for nextTickTime becomes intertwined with specific use cases of CCScheduler, which is only okay for now because CCDelayBasedTimeSource isn't used in many places.

Note: There is a comment in CCDelayBasedTimeSource.h indicating nextTickTime will return 0 if not active.  That comment should be changed to reflect the new behavior.
Comment 6 Brian Anderson 2012-08-22 12:59:27 PDT
Comment on attachment 159953 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=159953&action=review

> Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp:107
> +    return monotonicTimeNow() + m_currentParameters.interval;

jbates brought up a good point that this fake time will not be vsync aligned.  Could this cause the texture uploading to run long and prevent us from going active again ASAP?
Comment 7 David Reveman 2012-08-22 13:10:01 PDT
(In reply to comment #6)
> (From update of attachment 159953 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=159953&action=review
> 
> > Source/WebCore/platform/graphics/chromium/cc/CCDelayBasedTimeSource.cpp:107
> > +    return monotonicTimeNow() + m_currentParameters.interval;
> 
> jbates brought up a good point that this fake time will not be vsync aligned.  Could this cause the texture uploading to run long and prevent us from going active again ASAP?

It looks to me as if tickTarget always becomes "now + interval" when the timer goes from inactive to active state. Maybe I'm missing something?
Comment 8 David Reveman 2012-08-22 13:10:16 PDT
Created attachment 159996 [details]
Patch

Move comment to header
Comment 9 David Reveman 2012-08-22 13:17:14 PDT
(In reply to comment #5)
> I'm fine with getting this in, but would like to change it eventually, since it's lying about what the next tick time actually is.  Also, the behavior for nextTickTime becomes intertwined with specific use cases of CCScheduler, which is only okay for now because CCDelayBasedTimeSource isn't used in many places.

Would changing CCScheduler so that it always activates the timer before calling nextTickTime() be enough?

> 
> Note: There is a comment in CCDelayBasedTimeSource.h indicating nextTickTime will return 0 if not active.  That comment should be changed to reflect the new behavior.

Fixed in latest patch.
Comment 10 Brian Anderson 2012-08-22 13:45:14 PDT
> It looks to me as if tickTarget always becomes "now + interval" when the timer goes from inactive to active state. Maybe I'm missing something?

There is some additional logic in CCDelayBasedTimeSource::postNextTickTask that aligns "now" to the nearest vsync when the timer is activated.

> Would changing CCScheduler so that it always activates the timer before calling nextTickTime() be enough?

That would prevent us from lying and would also automatically align nextTickTime to a vsync.  We would end up with ticks that are no-ops, but the overhead should be negligible.  Sounds like a good trade off to me.
Comment 11 Nat Duca 2012-08-22 14:19:20 PDT
Recapping verbal discussion, how about reusing the lastTickTime of the DBTS?
Comment 12 David Reveman 2012-08-22 14:59:56 PDT
Created attachment 160016 [details]
Patch

Add nextTickTimeIfActivated and use postNextTickTask logic determine tick target when inactive
Comment 13 WebKit Review Bot 2012-08-22 15:10:36 PDT
Comment on attachment 160016 [details]
Patch

Attachment 160016 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/13561421
Comment 14 David Reveman 2012-08-22 15:29:51 PDT
Created attachment 160021 [details]
Patch

Fix unit test and ASSERT in postNextTickTask
Comment 15 Brian Anderson 2012-08-22 16:02:01 PDT
Comment on attachment 160021 [details]
Patch

New version looks good.  It returns a vsync aligned timestamp, the function name doesn't lie about what it's doing, and it doesn't spuriously activate ticking.
Comment 16 WebKit Review Bot 2012-08-23 08:42:11 PDT
Comment on attachment 160021 [details]
Patch

Clearing flags on attachment: 160021

Committed r126431: <http://trac.webkit.org/changeset/126431>
Comment 17 WebKit Review Bot 2012-08-23 08:42:15 PDT
All reviewed patches have been landed.  Closing bug.