Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/web_benchmarks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 0.1.0+12
## 1.0.0

* **Breaking change:** replace 'useCanvasKit' parameter with 'compilationOptions'.
* Add the ability to run a benchmark with WebAssembly.

## 0.1.0+11
Expand Down
6 changes: 2 additions & 4 deletions packages/web_benchmarks/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,24 @@ const int defaultChromeDebugPort = 10000;
Future<BenchmarkResults> serveWebBenchmark({
required io.Directory benchmarkAppDirectory,
required String entryPoint,
required bool useCanvasKit,
int benchmarkServerPort = defaultBenchmarkServerPort,
int chromeDebugPort = defaultChromeDebugPort,
bool headless = true,
bool treeShakeIcons = true,
String initialPage = defaultInitialPage,
bool useWasm = false,
CompilationOptions compilationOptions = const CompilationOptions(),
}) async {
// Reduce logging level. Otherwise, package:webkit_inspection_protocol is way too spammy.
Logger.root.level = Level.INFO;

return BenchmarkServer(
benchmarkAppDirectory: benchmarkAppDirectory,
entryPoint: entryPoint,
useCanvasKit: useCanvasKit,
benchmarkServerPort: benchmarkServerPort,
chromeDebugPort: chromeDebugPort,
headless: headless,
compilationOptions: compilationOptions,
treeShakeIcons: treeShakeIcons,
initialPage: initialPage,
useWasm: useWasm,
).run();
}
44 changes: 35 additions & 9 deletions packages/web_benchmarks/lib/src/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ class BenchmarkServer {
BenchmarkServer({
required this.benchmarkAppDirectory,
required this.entryPoint,
required this.useCanvasKit,
required this.benchmarkServerPort,
required this.chromeDebugPort,
required this.headless,
required this.treeShakeIcons,
this.useWasm = false,
this.compilationOptions = const CompilationOptions(),
this.initialPage = defaultInitialPage,
});

Expand All @@ -73,11 +72,8 @@ class BenchmarkServer {
/// the app.
final String entryPoint;

/// Whether to build the app in CanvasKit mode.
final bool useCanvasKit;

/// Whether to build the app with dart2wasm.
final bool useWasm;
/// The compilation options to use for building the benchmark web app.
final CompilationOptions compilationOptions;

/// The port this benchmark server serves the app on.
final int benchmarkServerPort;
Expand Down Expand Up @@ -118,12 +114,12 @@ class BenchmarkServer {
'flutter',
'build',
'web',
if (useWasm) ...<String>[
if (compilationOptions.useWasm) ...<String>[
'--wasm',
'--wasm-opt=debug',
'--omit-type-checks',
],
if (useCanvasKit) '--web-renderer=canvaskit',
'--web-renderer=${compilationOptions.renderer.name}',
'--dart-define=FLUTTER_WEB_ENABLE_PROFILING=true',
if (!treeShakeIcons) '--no-tree-shake-icons',
'--profile',
Expand Down Expand Up @@ -343,3 +339,33 @@ class BenchmarkServer {
}
}
}

/// Compilation options for bulding a Flutter web app.
///
/// This object holds metadata that is used to determine how the benchmark app
/// should be built.
class CompilationOptions {
/// Creates a [CompilationOptions] object.
const CompilationOptions({
this.renderer = WebRenderer.html,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default should ABSOLUTELY be canvaskit. I'd say ditch the html option entirely!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is published. Maybe just default to canvaskit

this.useWasm = false,
});

/// The renderer to use for the build.
final WebRenderer renderer;

/// Whether to build the app with dart2wasm.
final bool useWasm;
}

/// The possible types of web renderers Flutter can build for.
enum WebRenderer {
/// The HTML web renderer.
html,

/// The CanvasKit web renderer.
canvaskit,

/// The SKIA Wasm web renderer.
skwasm,
}
2 changes: 1 addition & 1 deletion packages/web_benchmarks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: web_benchmarks
description: A benchmark harness for performance-testing Flutter apps in Chrome.
repository: https://github.com/flutter/packages/tree/main/packages/web_benchmarks
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+web_benchmarks%22
version: 0.1.0+12
version: 1.0.0

environment:
sdk: ">=3.2.0 <4.0.0"
Expand Down
8 changes: 4 additions & 4 deletions packages/web_benchmarks/testing/web_benchmarks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:test/test.dart';

import 'package:web_benchmarks/server.dart';
import 'package:web_benchmarks/src/common.dart';
import 'package:web_benchmarks/src/runner.dart';

Future<void> main() async {
test('Can run a web benchmark', () async {
Expand All @@ -30,7 +31,7 @@ Future<void> main() async {
await _runBenchmarks(
benchmarkNames: <String>['simple'],
entryPoint: 'lib/benchmarks/runner_simple.dart',
useWasm: true,
compilationOptions: const CompilationOptions(useWasm: true),
);
}, timeout: Timeout.none);
}
Expand All @@ -39,15 +40,14 @@ Future<void> _runBenchmarks({
required List<String> benchmarkNames,
required String entryPoint,
String initialPage = defaultInitialPage,
bool useWasm = false,
CompilationOptions compilationOptions = const CompilationOptions(),
}) async {
final BenchmarkResults taskResult = await serveWebBenchmark(
benchmarkAppDirectory: Directory('testing/test_app'),
entryPoint: entryPoint,
useCanvasKit: false,
treeShakeIcons: false,
initialPage: initialPage,
useWasm: useWasm,
compilationOptions: compilationOptions,
);

for (final String benchmarkName in benchmarkNames) {
Expand Down