Increase IO thread's priority on iOS to avoid stucks (flutter/engine#34568)

This commit is contained in:
Yang Chao 2022-07-12 01:59:04 +08:00 committed by GitHub
parent af05788509
commit 0136679fb8
2 changed files with 31 additions and 1 deletions

View File

@ -699,7 +699,7 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
host_config.io_config =
fml::Thread::ThreadConfig(flutter::ThreadHost::ThreadHostConfig::MakeThreadName(
flutter::ThreadHost::Type::IO, threadLabel.UTF8String),
fml::Thread::ThreadPriority::BACKGROUND);
fml::Thread::ThreadPriority::NORMAL);
return (flutter::ThreadHost){host_config};
}

View File

@ -6,6 +6,8 @@
#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>
#import <objc/runtime.h>
#import "flutter/common/settings.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterBinaryMessengerRelay.h"
@ -261,4 +263,32 @@ FLUTTER_ASSERT_ARC
[self waitForExpectationsWithTimeout:1 handler:nil];
}
- (void)testThreadPrioritySetCorrectly {
XCTestExpectation* prioritiesSet = [self expectationWithDescription:@"prioritiesSet"];
prioritiesSet.expectedFulfillmentCount = 3;
IMP mockSetThreadPriority =
imp_implementationWithBlock(^(NSThread* thread, double threadPriority) {
if ([thread.name hasSuffix:@".ui"]) {
XCTAssertEqual(threadPriority, 1.0);
[prioritiesSet fulfill];
} else if ([thread.name hasSuffix:@".raster"]) {
XCTAssertEqual(threadPriority, 1.0);
[prioritiesSet fulfill];
} else if ([thread.name hasSuffix:@".io"]) {
XCTAssertEqual(threadPriority, 0.5);
[prioritiesSet fulfill];
}
});
Method method = class_getInstanceMethod([NSThread class], @selector(setThreadPriority:));
IMP originalSetThreadPriority = method_getImplementation(method);
method_setImplementation(method, mockSetThreadPriority);
FlutterEngine* engine = [[FlutterEngine alloc] init];
[engine run];
[self waitForExpectationsWithTimeout:1 handler:nil];
method_setImplementation(method, originalSetThreadPriority);
}
@end