-
Notifications
You must be signed in to change notification settings - Fork 6k
Optimize UI & GPU thread QoS for iOS #15673
Conversation
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.
I agree with the intent of tweaking thread priorities but this should go in the platform view so all platforms get a chance to set these priorities for all engine managed threads.
The thing about not creating the GPU thread is inaccurate and must be left out of this patch.
@@ -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 comment
The 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 (QOS_CLASS_BACKGROUND
). I suggest exposing this via the platform view creation callback. That way, all platforms are given the opportunity to set thread priorities on all threads managed by the engine.
@@ -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 |
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.
It sounds like we'd want to do something more dynamic than just setting the QoS to User-Interactive across the board. For example, increasing the QoS of the GPU thread at vsync. |
I talked to @chinmaygarde in person. This sounds fine to me after making the changes he suggested. One point is that we could add a priority to PostTask but most of our tasks are already divided up by priority based on what thread they are on. For example, you wouldn't want to run a low priority task on the GPU thread. @Qxyat can you post the before and after sample with your test case like you did in the PR description? |
This looks stale. I have filed flutter/flutter#63812 to track carrying this to completion. |
From the Instruments,we found that the UI & GPU thread run in a low priority, which may often be preempted by other thread and take less CPU time. For example:

The UI thread running time is 2.8s,but the preempted time is 4.18s。
According to the Apple documentation:https://developer.apple.com/library/archive/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html, the UI and GPU thread should be assigned to 'User-interactive', while the current QoS is 'Default'.
In addition, when the platform view is enabled, the GPU task runner is same as the platform task runner.So we should not create another GPU thread.