From 152dfb2fcf446574a697a703a759e810f8a654ea Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 25 Sep 2024 15:06:37 -0700 Subject: [PATCH] [engine] set platform thread name to ui. (flutter/engine#55362) When running with merged platform and ui threads, set the dart thread name of the main thread to io.futter.ui. Also change the thread mask settings to avoid creating an unused UI thread. --- engine/src/flutter/runtime/dart_isolate.cc | 12 +++++++++--- .../platform/android/android_shell_holder.cc | 16 ++++++++-------- .../ios/framework/Source/FlutterEngine.mm | 17 ++++++++--------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/engine/src/flutter/runtime/dart_isolate.cc b/engine/src/flutter/runtime/dart_isolate.cc index 3dc8403506f..4af4758d615 100644 --- a/engine/src/flutter/runtime/dart_isolate.cc +++ b/engine/src/flutter/runtime/dart_isolate.cc @@ -633,10 +633,16 @@ bool DartIsolate::UpdateThreadPoolNames() const { } if (auto task_runner = task_runners.GetPlatformTaskRunner()) { + bool is_merged_platform_ui_thread = + task_runner == task_runners.GetUITaskRunner(); + std::string label; + if (is_merged_platform_ui_thread) { + label = task_runners.GetLabel() + std::string{".ui"}; + } else { + label = task_runners.GetLabel() + std::string{".platform"}; + } task_runner->PostTask( - [label = task_runners.GetLabel() + std::string{".platform"}]() { - Dart_SetThreadName(label.c_str()); - }); + [label = std::move(label)]() { Dart_SetThreadName(label.c_str()); }); } return true; diff --git a/engine/src/flutter/shell/platform/android/android_shell_holder.cc b/engine/src/flutter/shell/platform/android/android_shell_holder.cc index 49a969627d4..e86effe09bd 100644 --- a/engine/src/flutter/shell/platform/android/android_shell_holder.cc +++ b/engine/src/flutter/shell/platform/android/android_shell_holder.cc @@ -89,17 +89,17 @@ AndroidShellHolder::AndroidShellHolder( static size_t thread_host_count = 1; auto thread_label = std::to_string(thread_host_count++); - auto mask = - ThreadHost::Type::kUi | ThreadHost::Type::kRaster | ThreadHost::Type::kIo; + auto mask = ThreadHost::Type::kRaster | ThreadHost::Type::kIo; + if (!settings.merged_platform_ui_thread) { + mask |= ThreadHost::Type::kUi; + } flutter::ThreadHost::ThreadHostConfig host_config( thread_label, mask, AndroidPlatformThreadConfigSetter); - if (!settings.merged_platform_ui_thread) { - host_config.ui_config = fml::Thread::ThreadConfig( - flutter::ThreadHost::ThreadHostConfig::MakeThreadName( - flutter::ThreadHost::Type::kUi, thread_label), - fml::Thread::ThreadPriority::kDisplay); - } + host_config.ui_config = fml::Thread::ThreadConfig( + flutter::ThreadHost::ThreadHostConfig::MakeThreadName( + flutter::ThreadHost::Type::kUi, thread_label), + fml::Thread::ThreadPriority::kDisplay); host_config.raster_config = fml::Thread::ThreadConfig( flutter::ThreadHost::ThreadHostConfig::MakeThreadName( flutter::ThreadHost::Type::kRaster, thread_label), diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index b1ca5e66ae6..713d4fd0e28 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -792,8 +792,10 @@ static flutter::ThreadHost MakeThreadHost(NSString* thread_label, // initialized. fml::MessageLoop::EnsureInitializedForCurrentThread(); - uint32_t threadHostType = flutter::ThreadHost::Type::kUi | flutter::ThreadHost::Type::kRaster | - flutter::ThreadHost::Type::kIo; + uint32_t threadHostType = flutter::ThreadHost::Type::kRaster | flutter::ThreadHost::Type::kIo; + if (!settings.enable_impeller) { + threadHostType |= flutter::ThreadHost::Type::kUi; + } if ([FlutterEngine isProfilerEnabled]) { threadHostType = threadHostType | flutter::ThreadHost::Type::kProfiler; @@ -802,13 +804,10 @@ static flutter::ThreadHost MakeThreadHost(NSString* thread_label, flutter::ThreadHost::ThreadHostConfig host_config(thread_label.UTF8String, threadHostType, IOSPlatformThreadConfigSetter); - if (!settings.enable_impeller) { - host_config.ui_config = - fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName( - flutter::ThreadHost::Type::kUi, thread_label.UTF8String), - fml::Thread::ThreadPriority::kDisplay); - } - + host_config.ui_config = + fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName( + flutter::ThreadHost::Type::kUi, thread_label.UTF8String), + fml::Thread::ThreadPriority::kDisplay); host_config.raster_config = fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName( flutter::ThreadHost::Type::kRaster, thread_label.UTF8String),