From 1fec30efb6675240c87c87cef4e17fa68957f097 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 12 Sep 2019 12:45:53 -0700 Subject: [PATCH] Place existing dill into hot reload temp directory to boost initialization time (#40366) --- packages/flutter_tools/lib/src/resident_runner.dart | 10 ++++++++++ .../test/general.shard/resident_runner_test.dart | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index 4511ac28b7a..f4b35b592f5 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -530,6 +530,16 @@ abstract class ResidentRunner { if (!artifactDirectory.existsSync()) { artifactDirectory.createSync(recursive: true); } + // TODO(jonahwilliams): this is a temporary work around to regain some of + // the initialize from dill performance. Longer term, we should have a + // better way to determine where the appropriate dill file is, as this + // doesn't work for Android or macOS builds.} + if (dillOutputPath == null) { + final File existingDill = fs.file(fs.path.join('build', 'app.dill')); + if (existingDill.existsSync()) { + existingDill.copySync(fs.path.join(artifactDirectory.path, 'app.dill')); + } + } } @protected diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index 85cdca126a1..58c2bd5522c 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -35,6 +35,9 @@ void main() { setUp(() { testbed = Testbed(setup: () { + fs.file(fs.path.join('build', 'app.dill')) + ..createSync(recursive: true) + ..writeAsStringSync('ABC'); residentRunner = HotRunner( [ mockFlutterDevice, @@ -193,6 +196,10 @@ void main() { Usage: () => MockUsage(), })); + test('ResidentRunner copies dill file from build output into temp directory', () => testbed.run(() async { + expect(residentRunner.artifactDirectory.childFile('app.dill').readAsStringSync(), 'ABC'); + })); + test('ResidentRunner can send target platform to analytics from hot reload', () => testbed.run(() async { when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation invocation) async { return 'Example';