Unverified Commit 6d6ada14 authored by Stanislav Baranov's avatar Stanislav Baranov Committed by GitHub

Friendlier flags for Dart compilation training. (#25645)

* Renamed --save-compilation-trace to flutter run --train.
* Renamed --precompile=<file> to --compilation-trace-file=<file>.
* In dynamic mode, made JIT snapshot the default, instead of kernel file.
parent 10ce6920
...@@ -318,8 +318,8 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -318,8 +318,8 @@ class FlutterPlugin implements Plugin<Project> {
trackWidgetCreationValue = project.property('track-widget-creation').toBoolean() trackWidgetCreationValue = project.property('track-widget-creation').toBoolean()
} }
String compilationTraceFilePathValue = null String compilationTraceFilePathValue = null
if (project.hasProperty('precompile')) { if (project.hasProperty('compilation-trace-file')) {
compilationTraceFilePathValue = project.property('precompile') compilationTraceFilePathValue = project.property('compilation-trace-file')
} }
Boolean createPatchValue = false Boolean createPatchValue = false
if (project.hasProperty('patch')) { if (project.hasProperty('patch')) {
...@@ -535,7 +535,7 @@ abstract class BaseFlutterTask extends DefaultTask { ...@@ -535,7 +535,7 @@ abstract class BaseFlutterTask extends DefaultTask {
args "--track-widget-creation" args "--track-widget-creation"
} }
if (compilationTraceFilePath != null) { if (compilationTraceFilePath != null) {
args "--precompile", compilationTraceFilePath args "--compilation-trace-file", compilationTraceFilePath
} }
if (createPatch) { if (createPatch) {
args "--patch" args "--patch"
......
...@@ -387,7 +387,7 @@ Future<void> _buildGradleProjectV2( ...@@ -387,7 +387,7 @@ Future<void> _buildGradleProjectV2(
assert(buildInfo.trackWidgetCreation != null); assert(buildInfo.trackWidgetCreation != null);
command.add('-Ptrack-widget-creation=${buildInfo.trackWidgetCreation}'); command.add('-Ptrack-widget-creation=${buildInfo.trackWidgetCreation}');
if (buildInfo.compilationTraceFilePath != null) if (buildInfo.compilationTraceFilePath != null)
command.add('-Pprecompile=${buildInfo.compilationTraceFilePath}'); command.add('-Pcompilation-trace-file=${buildInfo.compilationTraceFilePath}');
if (buildInfo.createPatch) if (buildInfo.createPatch)
command.add('-Ppatch=true'); command.add('-Ppatch=true');
if (buildInfo.extraFrontEndOptions != null) if (buildInfo.extraFrontEndOptions != null)
......
...@@ -73,6 +73,28 @@ Future<void> build({ ...@@ -73,6 +73,28 @@ Future<void> build({
packagesPath ??= fs.path.absolute(PackageMap.globalPackagesPath); packagesPath ??= fs.path.absolute(PackageMap.globalPackagesPath);
applicationKernelFilePath ??= getDefaultApplicationKernelPath(trackWidgetCreation: trackWidgetCreation); applicationKernelFilePath ??= getDefaultApplicationKernelPath(trackWidgetCreation: trackWidgetCreation);
if (compilationTraceFilePath != null) {
if (buildMode != BuildMode.dynamicProfile && buildMode != BuildMode.dynamicRelease) {
// Silently ignore JIT snapshotting for those builds that don't support it.
compilationTraceFilePath = null;
} else if (compilationTraceFilePath.isEmpty) {
// Disable JIT snapshotting if flag is empty.
printStatus('JIT snapshot will be disabled for this build...');
compilationTraceFilePath = null;
} else if (!fs.file(compilationTraceFilePath).existsSync()) {
// Be forgiving if compilation trace file is missing.
printError('Warning: Ignoring missing compiler training file $compilationTraceFilePath...');
printStatus('JIT snapshot will not use compiler training...');
final File tmp = fs.systemTempDirectory.childFile('flutterEmptyCompilationTrace.txt');
compilationTraceFilePath = (tmp..createSync(recursive: true)).path;
} else {
printStatus('JIT snapshot will use compiler training file $compilationTraceFilePath...');
}
}
DevFSContent kernelContent; DevFSContent kernelContent;
if (!precompiledSnapshot) { if (!precompiledSnapshot) {
if ((extraFrontEndOptions != null) && extraFrontEndOptions.isNotEmpty) if ((extraFrontEndOptions != null) && extraFrontEndOptions.isNotEmpty)
......
...@@ -94,7 +94,7 @@ class BuildBundleCommand extends BuildSubCommand { ...@@ -94,7 +94,7 @@ class BuildBundleCommand extends BuildSubCommand {
precompiledSnapshot: argResults['precompiled'], precompiledSnapshot: argResults['precompiled'],
reportLicensedPackages: argResults['report-licensed-packages'], reportLicensedPackages: argResults['report-licensed-packages'],
trackWidgetCreation: argResults['track-widget-creation'], trackWidgetCreation: argResults['track-widget-creation'],
compilationTraceFilePath: argResults['precompile'], compilationTraceFilePath: argResults['compilation-trace-file'],
createPatch: argResults['patch'], createPatch: argResults['patch'],
buildNumber: buildNumber, buildNumber: buildNumber,
baselineDir: argResults['baseline-dir'], baselineDir: argResults['baseline-dir'],
......
...@@ -35,17 +35,17 @@ abstract class RunCommandBase extends FlutterCommand { ...@@ -35,17 +35,17 @@ abstract class RunCommandBase extends FlutterCommand {
..addOption('route', ..addOption('route',
help: 'Which route to load when running the app.', help: 'Which route to load when running the app.',
) )
..addFlag('save-compilation-trace', ..addFlag('train',
hide: !verboseHelp, hide: !verboseHelp,
negatable: false, negatable: false,
help: 'Save runtime compilation trace to a file.\n' help: 'Save Dart runtime compilation trace to a file. '
'Compilation trace will be saved to compilation.txt when \'flutter run\' exits. ' 'Compilation trace will be saved to a file specified by --compilation-trace-file '
'when \'flutter run --dynamic --profile --train\' exits. '
'This file contains a list of Dart symbols that were compiled by the runtime JIT ' 'This file contains a list of Dart symbols that were compiled by the runtime JIT '
'compiler up to that point. This file can be used in later --dynamic builds to ' 'compiler up to that point. This file can be used in subsequent --dynamic builds '
'precompile some code by the offline compiler, thus reducing application startup ' 'to precompile some code by the offline compiler. '
'latency at the cost of larger application package.\n' 'This flag is only allowed when running as --dynamic --profile (recommended) or '
'This flag is only allowed when running --dynamic --profile (recommended) or ' '--debug (may include unwanted debug symbols).'
'--debug mode.\n'
) )
..addOption('target-platform', ..addOption('target-platform',
defaultsTo: 'default', defaultsTo: 'default',
...@@ -315,10 +315,10 @@ class RunCommand extends RunCommandBase { ...@@ -315,10 +315,10 @@ class RunCommand extends RunCommandBase {
} }
} }
if (argResults['save-compilation-trace'] && if (argResults['train'] &&
getBuildMode() != BuildMode.debug && getBuildMode() != BuildMode.dynamicProfile) getBuildMode() != BuildMode.debug && getBuildMode() != BuildMode.dynamicProfile)
throwToolExit('Error: --save-compilation-trace is only allowed when running ' throwToolExit('Error: --train is only allowed when running as --dynamic --profile '
'--dynamic --profile (recommended) or --debug mode.'); '(recommended) or --debug (may include unwanted debug symbols).');
final List<FlutterDevice> flutterDevices = devices.map<FlutterDevice>((Device device) { final List<FlutterDevice> flutterDevices = devices.map<FlutterDevice>((Device device) {
return FlutterDevice( return FlutterDevice(
...@@ -345,7 +345,7 @@ class RunCommand extends RunCommandBase { ...@@ -345,7 +345,7 @@ class RunCommand extends RunCommandBase {
projectRootPath: argResults['project-root'], projectRootPath: argResults['project-root'],
packagesFilePath: globalResults['packages'], packagesFilePath: globalResults['packages'],
dillOutputPath: argResults['output-dill'], dillOutputPath: argResults['output-dill'],
saveCompilationTrace: argResults['save-compilation-trace'], saveCompilationTrace: argResults['train'],
stayResident: stayResident, stayResident: stayResident,
ipv6: ipv6, ipv6: ipv6,
); );
...@@ -358,7 +358,7 @@ class RunCommand extends RunCommandBase { ...@@ -358,7 +358,7 @@ class RunCommand extends RunCommandBase {
applicationBinary: applicationBinaryPath == null applicationBinary: applicationBinaryPath == null
? null ? null
: fs.file(applicationBinaryPath), : fs.file(applicationBinaryPath),
saveCompilationTrace: argResults['save-compilation-trace'], saveCompilationTrace: argResults['train'],
stayResident: stayResident, stayResident: stayResident,
ipv6: ipv6, ipv6: ipv6,
); );
......
...@@ -242,14 +242,13 @@ abstract class FlutterCommand extends Command<void> { ...@@ -242,14 +242,13 @@ abstract class FlutterCommand extends Command<void> {
} }
void addDynamicModeFlags({bool verboseHelp = false}) { void addDynamicModeFlags({bool verboseHelp = false}) {
argParser.addOption('precompile', argParser.addOption('compilation-trace-file',
defaultsTo: 'compilation.txt',
hide: !verboseHelp, hide: !verboseHelp,
help: 'Precompile functions specified in input file. This flag is only ' help: 'Filename of Dart compilation trace file. This file will be produced\n'
'allowed when using --dynamic. It takes a Dart compilation trace ' 'by \'flutter run --dynamic --profile --train\' and consumed by subsequent\n'
'file produced by the training run of the application. With this ' '--dynamic builds such as \'flutter build apk --dynamic\' to precompile\n'
'flag, instead of using default Dart VM snapshot provided by the ' 'some code by the offline compiler.'
'engine, the application will use its own snapshot that includes '
'additional compiled functions.'
); );
argParser.addFlag('patch', argParser.addFlag('patch',
hide: !verboseHelp, hide: !verboseHelp,
...@@ -381,8 +380,8 @@ abstract class FlutterCommand extends Command<void> { ...@@ -381,8 +380,8 @@ abstract class FlutterCommand extends Command<void> {
? argResults['flavor'] ? argResults['flavor']
: null, : null,
trackWidgetCreation: trackWidgetCreation, trackWidgetCreation: trackWidgetCreation,
compilationTraceFilePath: argParser.options.containsKey('precompile') compilationTraceFilePath: argParser.options.containsKey('compilation-trace-file')
? argResults['precompile'] ? argResults['compilation-trace-file']
: null, : null,
createBaseline: argParser.options.containsKey('baseline') createBaseline: argParser.options.containsKey('baseline')
? argResults['baseline'] ? argResults['baseline']
...@@ -647,23 +646,23 @@ abstract class FlutterCommand extends Command<void> { ...@@ -647,23 +646,23 @@ abstract class FlutterCommand extends Command<void> {
final bool dynamicFlag = argParser.options.containsKey('dynamic') final bool dynamicFlag = argParser.options.containsKey('dynamic')
? argResults['dynamic'] : false; ? argResults['dynamic'] : false;
final String compilationTraceFilePath = argParser.options.containsKey('precompile') final String compilationTraceFilePath = argParser.options.containsKey('compilation-trace-file')
? argResults['precompile'] : null; ? argResults['compilation-trace-file'] : null;
final bool createBaseline = argParser.options.containsKey('baseline') final bool createBaseline = argParser.options.containsKey('baseline')
? argResults['baseline'] : false; ? argResults['baseline'] : false;
final bool createPatch = argParser.options.containsKey('patch') final bool createPatch = argParser.options.containsKey('patch')
? argResults['patch'] : false; ? argResults['patch'] : false;
if (compilationTraceFilePath != null && getBuildMode() == BuildMode.debug)
throw ToolExit('Error: --precompile is not allowed when --debug is specified.');
if (compilationTraceFilePath != null && !dynamicFlag)
throw ToolExit('Error: --precompile is allowed only when --dynamic is specified.');
if (createBaseline && createPatch) if (createBaseline && createPatch)
throw ToolExit('Error: Only one of --baseline, --patch is allowed.'); throw ToolExit('Error: Only one of --baseline, --patch is allowed.');
if (createBaseline && !dynamicFlag)
throw ToolExit('Error: --baseline is allowed only when --dynamic is specified.');
if (createBaseline && compilationTraceFilePath == null) if (createBaseline && compilationTraceFilePath == null)
throw ToolExit('Error: --baseline is allowed only when --precompile is specified.'); throw ToolExit('Error: --baseline requires --compilation-trace-file to be specified.');
if (createPatch && !dynamicFlag)
throw ToolExit('Error: --patch is allowed only when --dynamic is specified.');
if (createPatch && compilationTraceFilePath == null) if (createPatch && compilationTraceFilePath == null)
throw ToolExit('Error: --patch is allowed only when --precompile is specified.'); throw ToolExit('Error: --patch requires --compilation-trace-file to be specified.');
} }
ApplicationPackageStore applicationPackages; ApplicationPackageStore applicationPackages;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment