From 707aa49e42db746a8f4528e4700fb9017c5969d8 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 23 Sep 2020 13:39:52 -0700 Subject: [PATCH] [flutter_tools] flush UI thread tasks before finishing hot restart (#66417) Improve our ability to measure the performance of hot restart. Also flush all UI thread tasks before calling the hot restart "complete" in benchmark mode. If this is successful at stabilizing the benchmarks, this should be enabled for "normal" hot restart so that we can accurately track execution time. --- packages/flutter_tools/lib/src/run_hot.dart | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index 7c559abe8e..1b10061d86 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -554,7 +554,11 @@ class HotRunner extends ResidentRunner { .catchError((dynamic error, StackTrace stackTrace) { // Do nothing on a SentinelException since it means the isolate // has already been killed. - }, test: (dynamic error) => error is vm_service.SentinelException)); + // Error code 105 indicates the isolate is not yet runnable, and might + // be triggered if the tool is attempting to kill the asset parsing + // isolate before it has finished starting up. + }, test: (dynamic error) => error is vm_service.SentinelException + || (error is vm_service.RPCError && error.code == 105))); } } await Future.wait(operations); @@ -568,7 +572,6 @@ class HotRunner extends ResidentRunner { // Send timing analytics. globals.flutterUsage.sendTiming('hot', 'restart', restartTimer.elapsed); - // In benchmark mode, make sure all stream notifications have finished. if (benchmarkMode) { final List> isolateNotifications = >[]; for (final FlutterDevice device in flutterDevices) { @@ -584,7 +587,17 @@ class HotRunner extends ResidentRunner { ); } await Future.wait(isolateNotifications); + final List> futures = >[]; + for (final FlutterDevice device in flutterDevices) { + final List views = await device.vmService.getFlutterViews(); + for (final FlutterView view in views) { + futures.add(device.vmService + .flushUIThreadTasks(uiIsolateId: view.uiIsolate.id)); + } + } + await Future.wait(futures); } + // Toggle the main dill name after successfully uploading. _swap =! _swap;