Skip to content

Commit

Permalink
Train frontend_server snapshot (flutter#4560)
Browse files Browse the repository at this point in the history
Reland 86430be with a fix for Windows build

Cuts 30% from hot-reload benchmarks with `--preview-dart-2`
  • Loading branch information
jensjoha authored and mraleph committed Jan 17, 2018
1 parent 7173a15 commit 6de9931
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 5 additions & 1 deletion frontend_server/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import("//third_party/dart/utils/application_snapshot.gni")

application_snapshot("frontend_server") {
main_dart = "bin/starter.dart"
deps = [
"$flutter_root/lib/snapshot:kernel_platform_files",
]
dot_packages = rebase_path(".packages")
training_args = [ "--train" ]
flutter_patched_sdk = rebase_path("$root_out_dir/flutter_patched_sdk")
training_args = [ "--train", "--sdk-root=$flutter_patched_sdk" ]

frontend_server_files = exec_script("//third_party/dart/tools/list_dart_files.py",
[ "absolute", rebase_path("."), ], "list lines")
Expand Down
11 changes: 11 additions & 0 deletions frontend_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ Future<int> starter(
}

if (options['train']) {
final String sdkRoot = options['sdk-root'];
options = _argParser.parse(<String>['--incremental', '--sdk-root=$sdkRoot']);
compiler ??= new _FrontendCompiler(output, printerFactory: binaryPrinterFactory);
await compiler.compile(Platform.script.toFilePath(), options, generator: generator);
compiler.acceptLastDelta();
await compiler.recompileDelta();
compiler.acceptLastDelta();
await compiler.recompileDelta();
compiler.acceptLastDelta();
await compiler.recompileDelta();
compiler.acceptLastDelta();
return 0;
}

Expand Down
6 changes: 4 additions & 2 deletions frontend_server/test/server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ class _MockedBinaryPrinter extends Mock implements BinaryPrinter {}

Future<int> main() async {
group('basic', () {
test('train completes', () async {
expect(await starter(<String>['--train']), equals(0));
final CompilerInterface compiler = new _MockedCompiler();

test('train with mocked compiler completes', () async {
expect(await starter(<String>['--train'], compiler: compiler), equals(0));
});
});

Expand Down

0 comments on commit 6de9931

Please sign in to comment.