forked from firka/flutter
Change the default optimization level to -O2 for wasm in release mode. (#162917)
As per the investigation in https://github.com/flutter/flutter/issues/162620, we determined that the soundness we gain from using `-O2` outweighs the perf benefits of `-O4`.
This commit is contained in:
@@ -21,15 +21,9 @@ sealed class WebCompilerConfig {
|
||||
/// Build environment flag for [sourceMaps].
|
||||
static const String kSourceMapsEnabled = 'SourceMaps';
|
||||
|
||||
/// Calculates the optimization level for dart2js/dart2wasm for the given
|
||||
/// Calculates the optimization level for the compiler for the given
|
||||
/// build mode.
|
||||
int optimizationLevelForBuildMode(BuildMode mode) =>
|
||||
optimizationLevel ??
|
||||
switch (mode) {
|
||||
BuildMode.debug => 0,
|
||||
BuildMode.profile || BuildMode.release => 4,
|
||||
BuildMode.jitRelease => throw ArgumentError('Invalid build mode for web'),
|
||||
};
|
||||
int optimizationLevelForBuildMode(BuildMode mode);
|
||||
|
||||
/// The compiler optimization level specified by the user.
|
||||
///
|
||||
@@ -111,13 +105,15 @@ class JsCompilerConfig extends WebCompilerConfig {
|
||||
];
|
||||
|
||||
@override
|
||||
int optimizationLevelForBuildMode(BuildMode mode) {
|
||||
final int level = super.optimizationLevelForBuildMode(mode);
|
||||
|
||||
// dart2js optimization level 0 is not well supported. Use
|
||||
// 1 instead.
|
||||
return level == 0 ? 1 : level;
|
||||
}
|
||||
int optimizationLevelForBuildMode(BuildMode mode) =>
|
||||
optimizationLevel ??
|
||||
switch (mode) {
|
||||
// dart2js optimization level 0 is not well supported. Use
|
||||
// 1 instead.
|
||||
BuildMode.debug => 1,
|
||||
BuildMode.profile || BuildMode.release => 4,
|
||||
BuildMode.jitRelease => throw ArgumentError('Invalid build mode for web'),
|
||||
};
|
||||
|
||||
/// Arguments to use in the full JS compile, but not CFE-only.
|
||||
///
|
||||
@@ -163,6 +159,19 @@ class WasmCompilerConfig extends WebCompilerConfig {
|
||||
@override
|
||||
CompileTarget get compileTarget => CompileTarget.wasm;
|
||||
|
||||
@override
|
||||
int optimizationLevelForBuildMode(BuildMode mode) =>
|
||||
optimizationLevel ??
|
||||
switch (mode) {
|
||||
BuildMode.debug => 0,
|
||||
|
||||
// The optimization level of O2 uses only sound optimizations. We default
|
||||
// to this level because our web benchmarks have shown that the difference
|
||||
// between O2 and O4 is marginal enough that we would prefer soundness here.
|
||||
BuildMode.profile || BuildMode.release => 2,
|
||||
BuildMode.jitRelease => throw ArgumentError('Invalid build mode for web'),
|
||||
};
|
||||
|
||||
List<String> toCommandOptions(BuildMode buildMode) {
|
||||
final bool stripSymbols = buildMode == BuildMode.release && stripWasm;
|
||||
return <String>[
|
||||
|
||||
Reference in New Issue
Block a user