Skip to content

Commit

Permalink
Remove toString() overrides in dart:ui/package:flutter in profi…
Browse files Browse the repository at this point in the history
…le/release mode on wasm/vm targets (#144763)

The flutter engine & framework can opt out of this optimization for
individual classes / class hierarchies via:

  * `@pragma(flutter:keep-to-string)`
  * `@pragma(flutter:keep-to-string-in-subtypes)`

Or by using the convenience constant `@keepToString` from `dart:ui`.

=> This aligns the build process more with g3 (which already does this)

Closes flutter/flutter#52759
  • Loading branch information
mkustermann authored Mar 8, 2024
1 parent 7018685 commit 7c89ec8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/flutter_tools/lib/src/build_system/targets/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,16 @@ class Dart2WasmTarget extends Dart2WebTarget {
decodeDartDefines(environment.defines, kDartDefines),
);

assert(buildMode == BuildMode.release || buildMode == BuildMode.profile);
final List<String> compilationArgs = <String>[
artifacts.getArtifactPath(Artifact.engineDartBinary, platform: TargetPlatform.web_javascript),
'compile',
'wasm',
'--packages=.dart_tool/package_config.json',
'--extra-compiler-option=--dart-sdk=$dartSdkPath',
'--extra-compiler-option=--platform=$platformFilePath',
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
if (compilerConfig.renderer == WebRendererMode.skwasm) ...<String>[
'--extra-compiler-option=--import-shared-memory',
'--extra-compiler-option=--shared-memory-max-pages=32768',
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_tools/lib/src/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,15 @@ List<String> buildModeOptions(BuildMode mode, List<String> dartDefines) =>
'-Ddart.vm.profile=true',
if (!dartDefines.any((String define) => define.startsWith('dart.vm.product')))
'-Ddart.vm.product=false',
'--delete-tostring-package-uri=dart:ui',
'--delete-tostring-package-uri=package:flutter',
...kDartCompilerExperiments,
],
BuildMode.release => <String>[
'-Ddart.vm.profile=false',
'-Ddart.vm.product=true',
'--delete-tostring-package-uri=dart:ui',
'--delete-tostring-package-uri=package:flutter',
...kDartCompilerExperiments,
],
_ => throw Exception('Unknown BuildMode: $mode')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const List<String> _kDart2WasmLinuxArgs = <String> [
'--packages=.dart_tool/package_config.json',
'--extra-compiler-option=--dart-sdk=Artifact.engineDartSdkPath.TargetPlatform.web_javascript',
'--extra-compiler-option=--platform=HostArtifact.webPlatformKernelFolder/dart2wasm_platform.dill',
'--extra-compiler-option=--delete-tostring-package-uri=dart:ui',
'--extra-compiler-option=--delete-tostring-package-uri=package:flutter',
];

void main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ void main() {
'--no-print-incremental-dependencies',
'-Ddart.vm.profile=true',
'-Ddart.vm.product=false',
'--delete-tostring-package-uri=dart:ui',
'--delete-tostring-package-uri=package:flutter',
'--no-link-platform',
'--aot',
'--tfa',
Expand Down Expand Up @@ -248,6 +250,8 @@ void main() {
'--no-print-incremental-dependencies',
'-Ddart.vm.profile=false',
'-Ddart.vm.product=true',
'--delete-tostring-package-uri=dart:ui',
'--delete-tostring-package-uri=package:flutter',
'--no-link-platform',
'--aot',
'--tfa',
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter_tools/test/general.shard/compile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,15 @@ void main() {
testWithoutContext('buildModeOptions removes matching profile define in profile mode', () {
expect(buildModeOptions(BuildMode.profile, <String>['dart.vm.profile=true']), <String>[
'-Ddart.vm.product=false',
'--delete-tostring-package-uri=dart:ui',
'--delete-tostring-package-uri=package:flutter',
]);
});

testWithoutContext('buildModeOptions removes both matching profile and release define in profile mode', () {
expect(buildModeOptions(BuildMode.profile, <String>['dart.vm.profile=false', 'dart.vm.product=true']), <String>[
'--delete-tostring-package-uri=dart:ui',
'--delete-tostring-package-uri=package:flutter',
]);
});
}

0 comments on commit 7c89ec8

Please sign in to comment.