This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Optimize UI & GPU thread QoS for iOS #15673
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,10 +409,6 @@ - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { | |
// initialized. | ||
fml::MessageLoop::EnsureInitializedForCurrentThread(); | ||
|
||
_threadHost = {threadLabel.UTF8String, // label | ||
flutter::ThreadHost::Type::UI | flutter::ThreadHost::Type::GPU | | ||
flutter::ThreadHost::Type::IO}; | ||
|
||
// Lambda captures by pointers to ObjC objects are fine here because the | ||
// create call is | ||
// synchronous. | ||
|
@@ -435,12 +431,18 @@ - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { | |
// TODO(amirh/chinmaygarde): remove this, and dynamically change the thread configuration. | ||
// https://github.com/flutter/flutter/issues/23975 | ||
|
||
_threadHost = {threadLabel.UTF8String, // label | ||
flutter::ThreadHost::Type::UI | flutter::ThreadHost::Type::IO}; | ||
|
||
flutter::TaskRunners task_runners(threadLabel.UTF8String, // label | ||
fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform | ||
fml::MessageLoop::GetCurrent().GetTaskRunner(), // gpu | ||
_threadHost.ui_thread->GetTaskRunner(), // ui | ||
_threadHost.io_thread->GetTaskRunner() // io | ||
); | ||
|
||
[self setupQualityOfService:task_runners]; | ||
|
||
// Create the shell. This is a blocking operation. | ||
_shell = flutter::Shell::Create(std::move(task_runners), // task runners | ||
std::move(windowData), // window data | ||
|
@@ -449,12 +451,19 @@ - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { | |
on_create_rasterizer // rasterzier creation | ||
); | ||
} else { | ||
_threadHost = {threadLabel.UTF8String, // label | ||
flutter::ThreadHost::Type::UI | flutter::ThreadHost::Type::GPU | | ||
flutter::ThreadHost::Type::IO}; | ||
|
||
flutter::TaskRunners task_runners(threadLabel.UTF8String, // label | ||
fml::MessageLoop::GetCurrent().GetTaskRunner(), // platform | ||
_threadHost.gpu_thread->GetTaskRunner(), // gpu | ||
_threadHost.ui_thread->GetTaskRunner(), // ui | ||
_threadHost.io_thread->GetTaskRunner() // io | ||
); | ||
|
||
[self setupQualityOfService:task_runners]; | ||
|
||
// Create the shell. This is a blocking operation. | ||
_shell = flutter::Shell::Create(std::move(task_runners), // task runners | ||
std::move(windowData), // window data | ||
|
@@ -682,6 +691,14 @@ - (void)setIsGpuDisabled:(BOOL)value { | |
_isGpuDisabled = value; | ||
} | ||
|
||
- (void)setupQualityOfService:(flutter::TaskRunners&)task_runners { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be done for all threads managed by the engine. This includes the IO thread as well as the worker task runners ( |
||
task_runners.GetUITaskRunner()->PostTask( | ||
[] { pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0); }); | ||
|
||
task_runners.GetGPUTaskRunner()->PostTask( | ||
[] { pthread_set_qos_class_self_np(QOS_CLASS_USER_INTERACTIVE, 0); }); | ||
} | ||
|
||
@end | ||
|
||
@implementation FlutterEngineRegistrar { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That the GPU thread will no longer be created when there are platform views in the scene is an artifact of a previous implementation. This has been fixed #16068 and will cause issues with that line of work.