Commit 26542d61 authored by Farah Charab's avatar Farah Charab Committed by Commit Bot

Scheduler Experiment: Speedup experiments by caching feature list.

base::FeatureList::IsEnabled call is relatively expensive, so we cache
the values of the features in the main thread.

Change-Id: Ic725ff1d695cf01150139240d4f1b60d8b9a72a7
Reviewed-on: https://chromium-review.googlesource.com/1109214
Commit-Queue: Farah Charab <farahcharab@chromium.org>
Reviewed-by: default avatarAlexander Timin <altimin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569594}
parent 6599d5ff
......@@ -715,19 +715,23 @@ TaskQueue::QueuePriority FrameSchedulerImpl::ComputePriority(
bool background_page_with_no_audio = !IsPageVisible() && !IsAudioPlaying();
if (background_page_with_no_audio) {
if (base::FeatureList::IsEnabled(kLowPriorityForBackgroundPages))
if (main_thread_scheduler_->scheduling_settings()
.low_priority_background_page)
return TaskQueue::QueuePriority::kLowPriority;
if (base::FeatureList::IsEnabled(kBestEffortPriorityForBackgroundPages))
if (main_thread_scheduler_->scheduling_settings()
.best_effort_background_page)
return TaskQueue::QueuePriority::kBestEffortPriority;
}
// If main thread is in the loading use case or if the priority experiments
// should take place at all times.
if (main_thread_scheduler_->IsLoading() ||
!base::FeatureList::IsEnabled(kExperimentOnlyWhenLoading)) {
!main_thread_scheduler_->scheduling_settings()
.experiment_only_when_loading) {
// Low priority feature enabled for hidden frame.
if (base::FeatureList::IsEnabled(kLowPriorityForHiddenFrame) &&
if (main_thread_scheduler_->scheduling_settings()
.low_priority_hidden_frame &&
!IsFrameVisible())
return TaskQueue::QueuePriority::kLowPriority;
......@@ -737,16 +741,19 @@ TaskQueue::QueuePriority FrameSchedulerImpl::ComputePriority(
MainThreadTaskQueue::QueueType::kFrameThrottleable;
// Low priority feature enabled for sub-frame.
if (base::FeatureList::IsEnabled(kLowPriorityForSubFrame) && is_subframe)
if (main_thread_scheduler_->scheduling_settings().low_priority_subframe &&
is_subframe)
return TaskQueue::QueuePriority::kLowPriority;
// Low priority feature enabled for sub-frame throttleable task queues.
if (base::FeatureList::IsEnabled(kLowPriorityForSubFrameThrottleableTask) &&
if (main_thread_scheduler_->scheduling_settings()
.low_priority_subframe_throttleable &&
is_throttleable_task_queue)
return TaskQueue::QueuePriority::kLowPriority;
// Low priority feature enabled for throttleable task queues.
if (base::FeatureList::IsEnabled(kLowPriorityForThrottleableTask) &&
if (main_thread_scheduler_->scheduling_settings()
.low_priority_throttleable &&
is_throttleable_task_queue)
return TaskQueue::QueuePriority::kLowPriority;
}
......
......@@ -235,10 +235,6 @@ const char* OptionalTaskPriorityToString(
return TaskQueue::PriorityToString(priority.value());
}
bool IsUnconditionalHighPriorityInputEnabled() {
return base::FeatureList::IsEnabled(kHighPriorityInput);
}
bool IsBlockingEvent(const blink::WebInputEvent& web_input_event) {
blink::WebInputEvent::Type type = web_input_event.GetType();
DCHECK(type == blink::WebInputEvent::kTouchStart ||
......@@ -283,7 +279,7 @@ MainThreadSchedulerImpl::MainThreadSchedulerImpl(
MainThreadTaskQueue::QueueType::kInput)
.SetShouldMonitorQuiescence(true)
.SetFixedPriority(
IsUnconditionalHighPriorityInputEnabled()
scheduling_settings_.high_priority_input
? base::make_optional(
TaskQueue::QueuePriority::kHighestPriority)
: base::nullopt))),
......@@ -625,6 +621,26 @@ MainThreadSchedulerImpl::AnyThread::AnyThread(
&main_thread_scheduler_impl->tracing_controller_,
YesNoStateToString) {}
MainThreadSchedulerImpl::SchedulingSettings::SchedulingSettings() {
high_priority_input = base::FeatureList::IsEnabled(kHighPriorityInput);
low_priority_background_page =
base::FeatureList::IsEnabled(kLowPriorityForBackgroundPages);
best_effort_background_page =
base::FeatureList::IsEnabled(kBestEffortPriorityForBackgroundPages);
low_priority_hidden_frame =
base::FeatureList::IsEnabled(kLowPriorityForHiddenFrame);
low_priority_subframe = base::FeatureList::IsEnabled(kLowPriorityForSubFrame);
low_priority_throttleable =
base::FeatureList::IsEnabled(kLowPriorityForThrottleableTask);
low_priority_subframe_throttleable =
base::FeatureList::IsEnabled(kLowPriorityForSubFrameThrottleableTask);
experiment_only_when_loading =
base::FeatureList::IsEnabled(kExperimentOnlyWhenLoading);
}
MainThreadSchedulerImpl::AnyThread::~AnyThread() = default;
MainThreadSchedulerImpl::CompositorThreadOnly::CompositorThreadOnly()
......@@ -2753,6 +2769,11 @@ bool MainThreadSchedulerImpl::IsLoading() const {
return main_thread_only().current_use_case == UseCase::kLoading;
}
const MainThreadSchedulerImpl::SchedulingSettings&
MainThreadSchedulerImpl::scheduling_settings() const {
return scheduling_settings_;
}
// static
const char* MainThreadSchedulerImpl::UseCaseToString(UseCase use_case) {
switch (use_case) {
......
......@@ -83,6 +83,26 @@ class PLATFORM_EXPORT MainThreadSchedulerImpl
}
};
struct SchedulingSettings {
SchedulingSettings();
// High priority input experiment.
bool high_priority_input;
// Background page priority experiment.
bool low_priority_background_page;
bool best_effort_background_page;
// Task and subframe priority experiment.
bool low_priority_subframe;
bool low_priority_throttleable;
bool low_priority_subframe_throttleable;
bool low_priority_hidden_frame;
// Turn on relevant experiments during the loading phase.
bool experiment_only_when_loading;
};
static const char* UseCaseToString(UseCase use_case);
static const char* RAILModeToString(v8::RAILMode rail_mode);
static const char* VirtualTimePolicyToString(
......@@ -325,6 +345,8 @@ class PLATFORM_EXPORT MainThreadSchedulerImpl
// Returns true if main thread is in loading use case.
bool IsLoading() const;
const SchedulingSettings& scheduling_settings() const;
base::WeakPtr<MainThreadSchedulerImpl> GetWeakPtr();
protected:
......@@ -353,6 +375,7 @@ class PLATFORM_EXPORT MainThreadSchedulerImpl
friend class main_thread_scheduler_impl_unittest::
MainThreadSchedulerImplForTest;
friend class main_thread_scheduler_impl_unittest::MainThreadSchedulerImplTest;
FRIEND_TEST_ALL_PREFIXES(
main_thread_scheduler_impl_unittest::MainThreadSchedulerImplTest,
ShouldIgnoreTaskForUkm);
......@@ -691,6 +714,14 @@ class PLATFORM_EXPORT MainThreadSchedulerImpl
// because they require one to initialize themselves.
TraceableVariableController tracing_controller_;
// Used for experiments on finch. On main thread instantiation, we cache
// the values of base::Feature flags using this struct, since calling
// base::Feature::IsEnabled is a relatively expensive operation.
//
// Note that it is important to keep this as the first member to ensure it is
// initialized first and can be used everywhere.
const SchedulingSettings scheduling_settings_;
MainThreadSchedulerHelper helper_;
IdleHelper idle_helper_;
IdleCanceledDelayedTaskSweeper idle_canceled_delayed_task_sweeper_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment