summaryrefslogtreecommitdiffstats
path: root/base/message_loop.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/message_loop.cc')
-rw-r--r--base/message_loop.cc18
1 files changed, 14 insertions, 4 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc
index b20e6b6..b860fd8 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -542,13 +542,23 @@ bool MessageLoop::DoWork() {
bool MessageLoop::DoDelayedWork(base::Time* next_delayed_work_time) {
if (!nestable_tasks_allowed_ || delayed_work_queue_.empty()) {
- *next_delayed_work_time = base::Time();
+ recent_time_ = *next_delayed_work_time = base::Time();
return false;
}
- if (delayed_work_queue_.top().delayed_run_time > Time::Now()) {
- *next_delayed_work_time = delayed_work_queue_.top().delayed_run_time;
- return false;
+ // When we "fall behind," there may be a lot of tasks in the delayed work
+ // queue that are ready to run. To increase efficiency when we fall behind,
+ // we will only call Time::Now() intermittently, and then process all tasks
+ // that are ready to run before calling it again. As a result, the more we
+ // fall behind (and have a lot of ready-to-run delayed tasks), the more
+ // efficient we'll be at handling the tasks.
+ base::Time next_run_time = delayed_work_queue_.top().delayed_run_time;
+ if (next_run_time > recent_time_) {
+ recent_time_ = base::Time::Now(); // Get a better view of Now().
+ if (next_run_time > recent_time_) {
+ *next_delayed_work_time = next_run_time;
+ return false;
+ }
}
PendingTask pending_task = delayed_work_queue_.top();