summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorbrucedawson <brucedawson@chromium.org>2015-05-22 20:12:05 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-23 03:12:30 +0000
commit932c2457349e44eeb7b3152f8b49acd186e7057e (patch)
treee3f0fcb04553562271c330e68593a4b35a5c5055 /base
parent51f8b8eaa761940a54804181590d046124bb1776 (diff)
downloadchromium_src-932c2457349e44eeb7b3152f8b49acd186e7057e.zip
chromium_src-932c2457349e44eeb7b3152f8b49acd186e7057e.tar.gz
chromium_src-932c2457349e44eeb7b3152f8b49acd186e7057e.tar.bz2
Set minimum Windows wait time to 1 ms in MessagePumpDefault::Run
On Windows if we call event_.TimedWait(delay); with a sub-ms delay then the wait function will return immediately. This means we end up busy waiting down to zero. Rounding these times up to 1 ms lets Chrome go idle and saves a few percent of a core on some tests. The symptom to watch for is lots of time being spent in QPCNow, called from MessagePumpDefault::Run or from MessageLoop::DoDelayedWork. This is the second attempt at fixing this bug. The first attempt tried rounding down the short delays but this was stymied by other code that didn't respect the rounding down. One known problem is that some animations that try to run at 60 fps by using setInterval(C,16) will drop from ~60 fps to ~58 fps. Those that use requestAnimationFrame run at a steady rate of 60 fps. BUG=487724 Review URL: https://codereview.chromium.org/1154953002 Cr-Commit-Position: refs/heads/master@{#331226}
Diffstat (limited to 'base')
-rw-r--r--base/message_loop/message_pump_default.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/base/message_loop/message_pump_default.cc b/base/message_loop/message_pump_default.cc
index bb9d8ce..daa80d8 100644
--- a/base/message_loop/message_pump_default.cc
+++ b/base/message_loop/message_pump_default.cc
@@ -4,6 +4,8 @@
#include "base/message_loop/message_pump_default.h"
+#include <algorithm>
+
#include "base/logging.h"
#include "base/threading/thread_restrictions.h"
@@ -52,8 +54,14 @@ void MessagePumpDefault::Run(Delegate* delegate) {
event_.Wait();
} else {
TimeDelta delay = delayed_work_time_ - TimeTicks::Now();
- // If the delay is under 1 ms we need to execute the task right away.
- if (delay.InMilliseconds() >= 1) {
+#if defined(OS_WIN)
+ // If the delay is greater than zero and under 1 ms we need to round up to
+ // 1 ms or else we will end up spinning until it counts down to zero
+ // because sub-ms waits aren't supported on Windows.
+ if (delay > TimeDelta())
+ delay = std::max(delay, TimeDelta::FromMilliseconds(1));
+#endif
+ if (delay > TimeDelta()) {
event_.TimedWait(delay);
} else {
// It looks like delayed_work_time_ indicates a time in the past, so we