Skip to content

Commit 86430be

Browse files
jensjohamraleph
authored andcommitted
Train frontend_server snapshot (flutter#4512)
Cuts 30% from hot-reload benchmarks with `--preview-dart-2`
1 parent 73a9ea6 commit 86430be

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎frontend_server/BUILD.gn‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import("//third_party/dart/utils/application_snapshot.gni")
77
application_snapshot("frontend_server") {
88
main_dart = "bin/starter.dart"
99
dot_packages = rebase_path(".packages")
10-
training_args = [ "--train" ]
10+
flutter_patched_sdk = rebase_path("$root_out_dir/flutter_patched_sdk")
11+
training_args = [ "--train", "--sdk-root=$flutter_patched_sdk" ]
1112

1213
frontend_server_files = exec_script("//third_party/dart/tools/list_dart_files.py",
1314
[ "absolute", rebase_path("."), ], "list lines")

‎frontend_server/lib/server.dart‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,17 @@ Future<int> starter(
261261
}
262262

263263
if (options['train']) {
264+
final String sdkRoot = options['sdk-root'];
265+
options = _argParser.parse(<String>['--incremental', '--sdk-root=$sdkRoot']);
266+
compiler ??= new _FrontendCompiler(output, printerFactory: binaryPrinterFactory);
267+
await compiler.compile(Platform.script.toFilePath(), options, generator: generator);
268+
compiler.acceptLastDelta();
269+
await compiler.recompileDelta();
270+
compiler.acceptLastDelta();
271+
await compiler.recompileDelta();
272+
compiler.acceptLastDelta();
273+
await compiler.recompileDelta();
274+
compiler.acceptLastDelta();
264275
return 0;
265276
}
266277

‎frontend_server/test/server_test.dart‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class _MockedBinaryPrinter extends Mock implements BinaryPrinter {}
2626

2727
Future<int> main() async {
2828
group('basic', () {
29-
test('train completes', () async {
30-
expect(await starter(<String>['--train']), equals(0));
29+
final CompilerInterface compiler = new _MockedCompiler();
30+
31+
test('train with mocked compiler completes', () async {
32+
expect(await starter(<String>['--train'], compiler: compiler), equals(0));
3133
});
3234
});
3335

0 commit comments

Comments
 (0)