From dded2c661060371215ee1c9816c9394f6d39788d Mon Sep 17 00:00:00 2001 From: "mbelshe@google.com" Date: Tue, 15 Sep 2009 21:10:48 +0000 Subject: Issue 172109: Enable scavenging in RenderThread::IdleHandler. Landing of Anton Muhin's patch (antonm@google.com) BUG=none TEST=none Review URL: http://codereview.chromium.org/206017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26264 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/renderer/DEPS | 1 + chrome/renderer/render_thread.cc | 40 ++++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) (limited to 'chrome/renderer') diff --git a/chrome/renderer/DEPS b/chrome/renderer/DEPS index 4012ed4..f8b66fe 100644 --- a/chrome/renderer/DEPS +++ b/chrome/renderer/DEPS @@ -13,6 +13,7 @@ include_rules = [ "+webkit/glue/plugins", "+v8/include", "+third_party/sqlite/preprocessed", + "+third_party/tcmalloc", # FIXME - refactor code and remove these dependencies "+chrome/browser/net", diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index fd076ba..e7c04ed 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -48,6 +48,7 @@ #include "webkit/extensions/v8/gears_extension.h" #include "webkit/extensions/v8/interval_extension.h" #include "webkit/extensions/v8/playback_extension.h" +#include "third_party/tcmalloc/google/malloc_extension.h" #if defined(OS_WIN) #include @@ -459,26 +460,29 @@ void RenderThread::IdleHandler() { if (!widget_count_ || hidden_widget_count_ < widget_count_) return; - if (v8::V8::IsDead()) - return; - - LOG(INFO) << "RenderThread calling v8 IdleNotification for " << this; - - // When V8::IdleNotification returns true, it means that it has cleaned up - // as much as it can. There is no point in continuing to call it. - if (!v8::V8::IdleNotification(false)) { - // Dampen the delay using the algorithm: - // delay = delay + 1 / (delay + 2) - // Using floor(delay) has a dampening effect such as: - // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... - idle_notification_delay_in_s_ += - 1.0 / (idle_notification_delay_in_s_ + 2.0); +#if defined(OS_WIN) + MallocExtension::instance()->Scavenge(); +#endif - // Schedule the next timer. - MessageLoop::current()->PostDelayedTask(FROM_HERE, - task_factory_->NewRunnableMethod(&RenderThread::IdleHandler), - static_cast(floor(idle_notification_delay_in_s_)) * 1000); + if (!v8::V8::IsDead()) { + LOG(INFO) << "RenderThread calling v8 IdleNotification for " << this; + v8::V8::IdleNotification(false); } + + // Schedule next invocation. + // Dampen the delay using the algorithm: + // delay = delay + 1 / (delay + 2) + // Using floor(delay) has a dampening effect such as: + // 1s, 1, 1, 2, 2, 2, 2, 3, 3, ... + // Note that idle_notification_delay_in_s_ would be reset to + // kInitialIdleHandlerDelayS in RenderThread::WidgetHidden. + idle_notification_delay_in_s_ += + 1.0 / (idle_notification_delay_in_s_ + 2.0); + + // Schedule the next timer. + MessageLoop::current()->PostDelayedTask(FROM_HERE, + task_factory_->NewRunnableMethod(&RenderThread::IdleHandler), + static_cast(floor(idle_notification_delay_in_s_)) * 1000); } void RenderThread::OnExtensionMessageInvoke(const std::string& function_name, -- cgit v1.1