Bug 20979 - WebCore timers on Windows XP do not fire with high resolution
Summary: WebCore timers on Windows XP do not fire with high resolution
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows XP
: P2 Major
Assignee: Nobody
URL: http://ejohn.org/apps/timers/
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-21 16:46 PDT by Steve Falkenburg
Modified: 2008-09-21 17:14 PDT (History)
0 users

See Also:


Attachments
Use high-resolution date/time call in WebCore::currentTime, make SharedTimerWin OS agnostic (7.92 KB, patch)
2008-09-21 16:49 PDT, Steve Falkenburg
mjs: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Falkenburg 2008-09-21 16:46:05 PDT
Timers on XP are only firing at 16ms intervals.

On XP, the test at http://ejohn.org/apps/timers/ generates a line at 15-16ms. On Vista, we get a line at 10ms, which is expected given our timer clamp (we won't go any lower).

The bug is due to us not calling timeBeginPeriod/timeEndPeriod on XP, which we weren't doing since it didn't have the desired effect by itself.  The reason it wasn't working is that we're calling GetSystemTimeAsFileTime to retrieve the current time (to decide which timers are ready to fire).  Turns out on XP, this call is low resolution (15-16ms granularity), even when timeBeginPeriod/timeEndPeriod is used.

To fix this, we need to call timeBeginPeriod/timeEndPeriod on all systems (including both XP and Vista) and call through to our JSC high-resolution date/time code instead of using GetSystemTimeAsFileTime.  

Note that we don't call timeBeginPeriod(1) and leave it there. Instead, we want to fall back to low-resolution mode after 300ms or so to avoid overly taxing the user's CPU.
Comment 1 Steve Falkenburg 2008-09-21 16:49:00 PDT
Created attachment 23635 [details]
Use high-resolution date/time call in WebCore::currentTime, make SharedTimerWin OS agnostic
Comment 2 Maciej Stachowiak 2008-09-21 17:06:30 PDT
Comment on attachment 23635 [details]
Use high-resolution date/time call in WebCore::currentTime, make SharedTimerWin OS agnostic

r=me
Comment 3 mitz 2008-09-21 17:09:06 PDT
Comment on attachment 23635 [details]
Use high-resolution date/time call in WebCore::currentTime, make SharedTimerWin OS agnostic

-        if (wParam == sharedTimerID || wParam == lastChanceSharedTimerID && !isDeferringTimers()) {
+        if (wParam == sharedTimerID && !isDeferringTimers()) {

The !isDeferringTimers() check was only needed for the last chance timer.