From 7f3622ccea99fad4cc0b343e24f0b2f5f65307a9 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 26 Mar 2024 14:35:08 -0700 Subject: [PATCH] [iOS] remove arbitrary framerate cap. (flutter/engine#51663) This doesn't actually seem to be helping. For the most part, the frame time of the banners is steady with occassional spikes. Adding the framerate cap doesn't help the spikes, since those are in the 30+ ms frame time, and just results in everything else looking janky as well (especially if we dance around the cap, then we go 120 - 80) Since this is based on an arbitrary number, from an arbitrary app, on an arbitrary point in time we should remove it and instead try to fix the performance problems --- .../framework/Source/VsyncWaiterIosTest.mm | 84 ------------------- .../ios/framework/Source/vsync_waiter_ios.mm | 14 ---- 2 files changed, 98 deletions(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm index e8e254161b..c4a98258b8 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/VsyncWaiterIosTest.mm @@ -127,88 +127,4 @@ fml::RefPtr CreateNewThread(const std::string& name) { XCTAssertTrue(link.isPaused); } -- (void)testRefreshRateUpdatedTo80WhenThraedsMerge { - auto platform_thread_task_runner = CreateNewThread("Platform"); - auto raster_thread_task_runner = CreateNewThread("Raster"); - auto ui_thread_task_runner = CreateNewThread("UI"); - auto io_thread_task_runner = CreateNewThread("IO"); - auto task_runners = - flutter::TaskRunners("test", platform_thread_task_runner, raster_thread_task_runner, - ui_thread_task_runner, io_thread_task_runner); - - id mockDisplayLinkManager = [OCMockObject mockForClass:[DisplayLinkManager class]]; - double maxFrameRate = 120; - [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate]; - [[[mockDisplayLinkManager stub] andReturnValue:@(YES)] maxRefreshRateEnabledOnIPhone]; - auto vsync_waiter = flutter::VsyncWaiterIOS(task_runners); - - fml::scoped_nsobject vsyncClient = vsync_waiter.GetVsyncClient(); - CADisplayLink* link = [vsyncClient.get() getDisplayLink]; - - if (@available(iOS 15.0, *)) { - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.maximum, maxFrameRate, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.preferred, maxFrameRate, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.minimum, maxFrameRate / 2, 0.1); - } else { - XCTAssertEqualWithAccuracy(link.preferredFramesPerSecond, maxFrameRate, 0.1); - } - - const auto merger = fml::RasterThreadMerger::CreateOrShareThreadMerger( - nullptr, platform_thread_task_runner->GetTaskQueueId(), - raster_thread_task_runner->GetTaskQueueId()); - - merger->MergeWithLease(5); - vsync_waiter.AwaitVSync(); - - if (@available(iOS 15.0, *)) { - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.maximum, 80, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.preferred, 80, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.minimum, 60, 0.1); - } else { - XCTAssertEqualWithAccuracy(link.preferredFramesPerSecond, 80, 0.1); - } - - merger->UnMergeNowIfLastOne(); - vsync_waiter.AwaitVSync(); - - if (@available(iOS 15.0, *)) { - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.maximum, maxFrameRate, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.preferred, maxFrameRate, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.minimum, maxFrameRate / 2, 0.1); - } else { - XCTAssertEqualWithAccuracy(link.preferredFramesPerSecond, maxFrameRate, 0.1); - } - - if (@available(iOS 14.0, *)) { - // Fake response that we are running on Mac. - id processInfo = [NSProcessInfo processInfo]; - id processInfoPartialMock = OCMPartialMock(processInfo); - bool iOSAppOnMac = true; - [OCMStub([processInfoPartialMock isiOSAppOnMac]) andReturnValue:OCMOCK_VALUE(iOSAppOnMac)]; - - merger->MergeWithLease(5); - vsync_waiter.AwaitVSync(); - - // On Mac, framerate should be uncapped. - if (@available(iOS 15.0, *)) { - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.maximum, maxFrameRate, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.preferred, maxFrameRate, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.minimum, maxFrameRate / 2, 0.1); - } else { - XCTAssertEqualWithAccuracy(link.preferredFramesPerSecond, 80, 0.1); - } - - merger->UnMergeNowIfLastOne(); - vsync_waiter.AwaitVSync(); - - if (@available(iOS 15.0, *)) { - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.maximum, maxFrameRate, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.preferred, maxFrameRate, 0.1); - XCTAssertEqualWithAccuracy(link.preferredFrameRateRange.minimum, maxFrameRate / 2, 0.1); - } else { - XCTAssertEqualWithAccuracy(link.preferredFramesPerSecond, maxFrameRate, 0.1); - } - } -} - @end diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm index 3396d1fc70..5171bf9153 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/vsync_waiter_ios.mm @@ -41,20 +41,6 @@ VsyncWaiterIOS::~VsyncWaiterIOS() { void VsyncWaiterIOS::AwaitVSync() { double new_max_refresh_rate = [DisplayLinkManager displayRefreshRate]; - if (fml::TaskRunnerChecker::RunsOnTheSameThread( - task_runners_.GetRasterTaskRunner()->GetTaskQueueId(), - task_runners_.GetPlatformTaskRunner()->GetTaskQueueId())) { - BOOL isRunningOnMac = NO; - if (@available(iOS 14.0, *)) { - isRunningOnMac = [NSProcessInfo processInfo].iOSAppOnMac; - } - if (!isRunningOnMac) { - // Pressure tested on iPhone 13 pro, the oldest iPhone that supports refresh rate greater than - // 60fps. A flutter app can handle fast scrolling on 80 fps with 6 PlatformViews in the scene - // at the same time. - new_max_refresh_rate = 80; - } - } if (fabs(new_max_refresh_rate - max_refresh_rate_) > kRefreshRateDiffToIgnore) { max_refresh_rate_ = new_max_refresh_rate; [client_.get() setMaxRefreshRate:max_refresh_rate_];