Unverified Commit b3014ff5 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

add profile mode to flutter web applications (#39073)

parent b2d19d2a
...@@ -38,6 +38,8 @@ const String digestsEntrypointExtension = '.digests'; ...@@ -38,6 +38,8 @@ const String digestsEntrypointExtension = '.digests';
const String jsModuleErrorsExtension = '.ddc.js.errors'; const String jsModuleErrorsExtension = '.ddc.js.errors';
const String jsModuleExtension = '.ddc.js'; const String jsModuleExtension = '.ddc.js';
const String jsSourceMapExtension = '.ddc.js.map'; const String jsSourceMapExtension = '.ddc.js.map';
const String kReleaseFlag = 'release';
const String kProfileFlag = 'profile';
final DartPlatform flutterWebPlatform = final DartPlatform flutterWebPlatform =
DartPlatform.register('flutter_web', <String>[ DartPlatform.register('flutter_web', <String>[
...@@ -141,7 +143,8 @@ final List<core.BuilderApplication> builders = <core.BuilderApplication>[ ...@@ -141,7 +143,8 @@ final List<core.BuilderApplication> builders = <core.BuilderApplication>[
'flutter_tools:entrypoint', 'flutter_tools:entrypoint',
<BuilderFactory>[ <BuilderFactory>[
(BuilderOptions options) => FlutterWebEntrypointBuilder( (BuilderOptions options) => FlutterWebEntrypointBuilder(
options.config['release'] ?? false, options.config[kReleaseFlag] ?? false,
options.config[kProfileFlag] ?? false,
options.config['flutterWebSdk'], options.config['flutterWebSdk'],
), ),
], ],
...@@ -201,9 +204,10 @@ class FlutterWebTestEntrypointBuilder implements Builder { ...@@ -201,9 +204,10 @@ class FlutterWebTestEntrypointBuilder implements Builder {
/// A ddc-only entrypoint builder that respects the Flutter target flag. /// A ddc-only entrypoint builder that respects the Flutter target flag.
class FlutterWebEntrypointBuilder implements Builder { class FlutterWebEntrypointBuilder implements Builder {
const FlutterWebEntrypointBuilder(this.release, this.flutterWebSdk); const FlutterWebEntrypointBuilder(this.release, this.profile, this.flutterWebSdk);
final bool release; final bool release;
final bool profile;
final String flutterWebSdk; final String flutterWebSdk;
@override @override
...@@ -219,8 +223,8 @@ class FlutterWebEntrypointBuilder implements Builder { ...@@ -219,8 +223,8 @@ class FlutterWebEntrypointBuilder implements Builder {
@override @override
Future<void> build(BuildStep buildStep) async { Future<void> build(BuildStep buildStep) async {
if (release) { if (release || profile) {
await bootstrapDart2Js(buildStep, flutterWebSdk); await bootstrapDart2Js(buildStep, flutterWebSdk, profile);
} else { } else {
await bootstrapDdc(buildStep, platform: flutterWebPlatform); await bootstrapDdc(buildStep, platform: flutterWebPlatform);
} }
...@@ -366,7 +370,7 @@ Future<void> main() async { ...@@ -366,7 +370,7 @@ Future<void> main() async {
}; };
} }
Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk) async { Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk, bool profile) async {
final AssetId dartEntrypointId = buildStep.inputId; final AssetId dartEntrypointId = buildStep.inputId;
final AssetId moduleId = dartEntrypointId.changeExtension(moduleExtension(flutterWebPlatform)); final AssetId moduleId = dartEntrypointId.changeExtension(moduleExtension(flutterWebPlatform));
final Module module = Module.fromJson(json.decode(await buildStep.readAsString(moduleId))); final Module module = Module.fromJson(json.decode(await buildStep.readAsString(moduleId)));
...@@ -388,10 +392,16 @@ Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk) async { ...@@ -388,10 +392,16 @@ Future<void> bootstrapDart2Js(BuildStep buildStep, String flutterWebSdk) async {
final String librariesPath = path.join(flutterWebSdkPath, 'libraries.json'); final String librariesPath = path.join(flutterWebSdkPath, 'libraries.json');
final List<String> args = <String>[ final List<String> args = <String>[
'--libraries-spec="$librariesPath"', '--libraries-spec="$librariesPath"',
if (profile)
'-O1'
else
'-O4', '-O4',
'-o', '-o',
'$jsOutputPath', '$jsOutputPath',
'--packages="$packageFile"', '--packages="$packageFile"',
if (profile)
'-Ddart.vm.profile=true'
else
'-Ddart.vm.product=true', '-Ddart.vm.product=true',
dartPath, dartPath,
]; ];
......
...@@ -140,7 +140,7 @@ class WebFs { ...@@ -140,7 +140,7 @@ class WebFs {
}) async { }) async {
// Start the build daemon and run an initial build. // Start the build daemon and run an initial build.
final BuildDaemonClient client = await buildDaemonCreator final BuildDaemonClient client = await buildDaemonCreator
.startBuildDaemon(fs.currentDirectory.path, release: buildInfo.isRelease); .startBuildDaemon(fs.currentDirectory.path, release: buildInfo.isRelease, profile: buildInfo.isProfile);
client.startBuild(); client.startBuild();
// Only provide relevant build results // Only provide relevant build results
final Stream<BuildResult> filteredBuildResults = client.buildResults final Stream<BuildResult> filteredBuildResults = client.buildResults
...@@ -266,11 +266,12 @@ class BuildDaemonCreator { ...@@ -266,11 +266,12 @@ class BuildDaemonCreator {
const BuildDaemonCreator(); const BuildDaemonCreator();
/// Start a build daemon and register the web targets. /// Start a build daemon and register the web targets.
Future<BuildDaemonClient> startBuildDaemon(String workingDirectory, {bool release = false}) async { Future<BuildDaemonClient> startBuildDaemon(String workingDirectory, {bool release = false, bool profile = false }) async {
try { try {
final BuildDaemonClient client = await _connectClient( final BuildDaemonClient client = await _connectClient(
workingDirectory, workingDirectory,
release: release, release: release,
profile: profile,
); );
_registerBuildTargets(client); _registerBuildTargets(client);
return client; return client;
...@@ -297,7 +298,7 @@ class BuildDaemonCreator { ...@@ -297,7 +298,7 @@ class BuildDaemonCreator {
Future<BuildDaemonClient> _connectClient( Future<BuildDaemonClient> _connectClient(
String workingDirectory, String workingDirectory,
{ bool release } { bool release, bool profile }
) { ) {
final String flutterToolsPackages = fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools', '.packages'); final String flutterToolsPackages = fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools', '.packages');
final String buildScript = fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools', 'lib', 'src', 'build_runner', 'build_script.dart'); final String buildScript = fs.path.join(Cache.flutterRoot, 'packages', 'flutter_tools', 'lib', 'src', 'build_runner', 'build_script.dart');
...@@ -316,6 +317,7 @@ class BuildDaemonCreator { ...@@ -316,6 +317,7 @@ class BuildDaemonCreator {
'--define', 'flutter_tools:ddc=flutterWebSdk=$flutterWebSdk', '--define', 'flutter_tools:ddc=flutterWebSdk=$flutterWebSdk',
'--define', 'flutter_tools:entrypoint=flutterWebSdk=$flutterWebSdk', '--define', 'flutter_tools:entrypoint=flutterWebSdk=$flutterWebSdk',
'--define', 'flutter_tools:entrypoint=release=$release', '--define', 'flutter_tools:entrypoint=release=$release',
'--define', 'flutter_tools:entrypoint=profile=$profile',
'--define', 'flutter_tools:shell=flutterWebSdk=$flutterWebSdk', '--define', 'flutter_tools:shell=flutterWebSdk=$flutterWebSdk',
], ],
logHandler: (ServerLog serverLog) { logHandler: (ServerLog serverLog) {
......
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