summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authormarkus@chromium.org <markus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 23:53:51 +0000
committermarkus@chromium.org <markus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 23:53:51 +0000
commit545a8b0702d8054b669438e9ad3900c1b11a5123 (patch)
tree3b8c4847c2d2143cc430436ceebcb1877474ff17 /webkit/glue
parentecb0a024ee469a8d591fb95ac4f8db9c6217f462 (diff)
downloadchromium_src-545a8b0702d8054b669438e9ad3900c1b11a5123.zip
chromium_src-545a8b0702d8054b669438e9ad3900c1b11a5123.tar.gz
chromium_src-545a8b0702d8054b669438e9ad3900c1b11a5123.tar.bz2
When converting between units of time or data types of different precision,
we have to be careful to consistently round in the same direction. Timeout checks usually check if Now() is less or equal to a deadline in order to determine if a timeout has occurred. This correctly handles the case where actual sleep times are equal or longer than requested sleep times. But if we round down when setting the sleep delay, this can result in unnecessary and expensive looping. Make sure, we always round up when converting to a format with less precision. BUG=none TEST=none Review URL: http://codereview.chromium.org/196053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27146 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/webkitclient_impl.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc
index 4315db7..79ddffd6 100644
--- a/webkit/glue/webkitclient_impl.cc
+++ b/webkit/glue/webkitclient_impl.cc
@@ -2,6 +2,7 @@
// source code is governed by a BSD-style license that can be found in the
// LICENSE file.
+#include <math.h>
#include "config.h"
#include "FrameView.h"
@@ -265,12 +266,23 @@ void WebKitClientImpl::setSharedTimerFiredFunction(void (*func)()) {
}
void WebKitClientImpl::setSharedTimerFireTime(double fire_time) {
- int interval = static_cast<int>((fire_time - currentTime()) * 1000);
+ // By converting between double and int64 representation, we run the risk
+ // of losing precision due to rounding errors. Performing computations in
+ // microseconds reduces this risk somewhat. But there still is the potential
+ // of us computing a fire time for the timer that is shorter than what we
+ // need.
+ // As the event loop will check event deadlines prior to actually firing
+ // them, there is a risk of needlessly rescheduling events and of
+ // needlessly looping if sleep times are too short even by small amounts.
+ // This results in measurable performance degradation unless we use ceil() to
+ // always round up the sleep times.
+ int64 interval = static_cast<int64>(
+ ceil((fire_time - currentTime()) * base::Time::kMicrosecondsPerSecond));
if (interval < 0)
interval = 0;
shared_timer_.Stop();
- shared_timer_.Start(base::TimeDelta::FromMilliseconds(interval), this,
+ shared_timer_.Start(base::TimeDelta::FromMicroseconds(interval), this,
&WebKitClientImpl::DoTimeout);
}