forked from firka/flutter
Increase thread priority before engine init (flutter/engine#20922)
We get huge ANRs in not pure flutter app. We found that 0.15% of the engine initialization took more than 10 seconds, every 10 million starts.
This commit is contained in:
@@ -107,6 +107,23 @@ AndroidShellHolder::AndroidShellHolder(
|
|||||||
ui_runner, // ui
|
ui_runner, // ui
|
||||||
io_runner // io
|
io_runner // io
|
||||||
);
|
);
|
||||||
|
task_runners.GetRasterTaskRunner()->PostTask([]() {
|
||||||
|
// Android describes -8 as "most important display threads, for
|
||||||
|
// compositing the screen and retrieving input events". Conservatively
|
||||||
|
// set the raster thread to slightly lower priority than it.
|
||||||
|
if (::setpriority(PRIO_PROCESS, gettid(), -5) != 0) {
|
||||||
|
// Defensive fallback. Depending on the OEM, it may not be possible
|
||||||
|
// to set priority to -5.
|
||||||
|
if (::setpriority(PRIO_PROCESS, gettid(), -2) != 0) {
|
||||||
|
FML_LOG(ERROR) << "Failed to set GPU task runner priority";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
task_runners.GetUITaskRunner()->PostTask([]() {
|
||||||
|
if (::setpriority(PRIO_PROCESS, gettid(), -1) != 0) {
|
||||||
|
FML_LOG(ERROR) << "Failed to set UI task runner priority";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
shell_ =
|
shell_ =
|
||||||
Shell::Create(task_runners, // task runners
|
Shell::Create(task_runners, // task runners
|
||||||
@@ -118,28 +135,7 @@ AndroidShellHolder::AndroidShellHolder(
|
|||||||
|
|
||||||
platform_view_ = weak_platform_view;
|
platform_view_ = weak_platform_view;
|
||||||
FML_DCHECK(platform_view_);
|
FML_DCHECK(platform_view_);
|
||||||
|
|
||||||
is_valid_ = shell_ != nullptr;
|
is_valid_ = shell_ != nullptr;
|
||||||
|
|
||||||
if (is_valid_) {
|
|
||||||
shell_->GetTaskRunners().GetRasterTaskRunner()->PostTask([]() {
|
|
||||||
// Android describes -8 as "most important display threads, for
|
|
||||||
// compositing the screen and retrieving input events". Conservatively
|
|
||||||
// set the raster thread to slightly lower priority than it.
|
|
||||||
if (::setpriority(PRIO_PROCESS, gettid(), -5) != 0) {
|
|
||||||
// Defensive fallback. Depending on the OEM, it may not be possible
|
|
||||||
// to set priority to -5.
|
|
||||||
if (::setpriority(PRIO_PROCESS, gettid(), -2) != 0) {
|
|
||||||
FML_LOG(ERROR) << "Failed to set GPU task runner priority";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
shell_->GetTaskRunners().GetUITaskRunner()->PostTask([]() {
|
|
||||||
if (::setpriority(PRIO_PROCESS, gettid(), -1) != 0) {
|
|
||||||
FML_LOG(ERROR) << "Failed to set UI task runner priority";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AndroidShellHolder::~AndroidShellHolder() {
|
AndroidShellHolder::~AndroidShellHolder() {
|
||||||
|
|||||||
Reference in New Issue
Block a user