Skip to content

Add '--no-tree-shake-icons' option to BenchmarkServer #5186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions packages/web_benchmarks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.0+8

* Adds an optional parameter `treeShakeIcons` to `serveWebBenchmark`.
* Adds a required and named parameter `treeShakeIcons` to `BenchmarkServer`.

## 0.1.0+7

* Updates `package:process` version constraints.
Expand Down
2 changes: 2 additions & 0 deletions packages/web_benchmarks/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Future<BenchmarkResults> serveWebBenchmark({
int benchmarkServerPort = defaultBenchmarkServerPort,
int chromeDebugPort = defaultChromeDebugPort,
bool headless = true,
bool treeShakeIcons = true,
}) async {
// Reduce logging level. Otherwise, package:webkit_inspection_protocol is way too spammy.
Logger.root.level = Level.INFO;
Expand All @@ -57,5 +58,6 @@ Future<BenchmarkResults> serveWebBenchmark({
benchmarkServerPort: benchmarkServerPort,
chromeDebugPort: chromeDebugPort,
headless: headless,
treeShakeIcons: treeShakeIcons,
).run();
}
7 changes: 7 additions & 0 deletions packages/web_benchmarks/lib/src/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class BenchmarkServer {
required this.benchmarkServerPort,
required this.chromeDebugPort,
required this.headless,
required this.treeShakeIcons,
});

final ProcessManager _processManager = const LocalProcessManager();
Expand Down Expand Up @@ -84,6 +85,11 @@ class BenchmarkServer {
/// This is useful in environments (e.g. CI) that doesn't have a display.
final bool headless;

/// Whether to tree shake icons during the build.
///
/// When false, '--no-tree-shake-icons' will be passed as a build argument.
final bool treeShakeIcons;

/// Builds and serves the benchmark app, and collects benchmark results.
Future<BenchmarkResults> run() async {
// Reduce logging level. Otherwise, package:webkit_inspection_protocol is way too spammy.
Expand All @@ -101,6 +107,7 @@ class BenchmarkServer {
'web',
'--dart-define=FLUTTER_WEB_ENABLE_PROFILING=true',
if (useCanvasKit) '--dart-define=FLUTTER_WEB_USE_SKIA=true',
if (!treeShakeIcons) '--no-tree-shake-icons',
'--profile',
'-t',
entryPoint,
Expand Down
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+7
version: 0.1.0+8

environment:
sdk: ">=2.19.0 <4.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:web_benchmarks/client.dart';

import '../aboutpage.dart' show backKey;
import '../homepage.dart' show aboutPageKey, textKey;
import '../about_page.dart' show backKey;
import '../home_page.dart' show aboutPageKey, textKey;
import '../main.dart';

/// A recorder that measures frame building durations.
Expand Down
45 changes: 45 additions & 0 deletions packages/web_benchmarks/testing/test_app/lib/icon_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

class IconGeneratorPage extends StatefulWidget {
const IconGeneratorPage({super.key});

static int defaultIconCodePoint = int.parse('0xf03f');

@override
State<IconGeneratorPage> createState() => _IconGeneratorPageState();
}

class _IconGeneratorPageState extends State<IconGeneratorPage> {
int iconCodePoint = IconGeneratorPage.defaultIconCodePoint;

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
TextField(
onSubmitted: (String value) {
final int codePointAsInt =
int.tryParse(value) ?? IconGeneratorPage.defaultIconCodePoint;
setState(() {
iconCodePoint = codePointAsInt;
});
},
),
const SizedBox(height: 24.0),
Icon(generateIcon(iconCodePoint)),
],
);
}

// Unless '--no-tree-shake-icons' is passed to the flutter build command,
// the presence of this method will trigger an exception due to the use of
// non-constant invocations of [IconData].
IconData generateIcon(int materialIconCodePoint) => IconData(
materialIconCodePoint,
fontFamily: 'MaterialIcons',
);
}
6 changes: 4 additions & 2 deletions packages/web_benchmarks/testing/test_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

import 'package:flutter/material.dart';

import 'aboutpage.dart';
import 'homepage.dart';
import 'about_page.dart';
import 'home_page.dart';
import 'icon_page.dart';

void main() {
runApp(const MyApp());
Expand All @@ -26,6 +27,7 @@ class MyApp extends StatelessWidget {
routes: <String, WidgetBuilder>{
'home': (_) => const HomePage(title: 'Flutter Demo Home Page'),
'about': (_) => const AboutPage(),
'icon_generator': (_) => const IconGeneratorPage(),
},
);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/web_benchmarks/testing/test_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=2.19.0 <4.0.0"
sdk: '>=2.19.0 <4.0.0'

dependencies:
cupertino_icons: ^1.0.5
flutter:
sdk: flutter
flutter_test:
Expand Down
1 change: 1 addition & 0 deletions packages/web_benchmarks/testing/web_benchmarks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Future<void> main() async {
benchmarkAppDirectory: Directory('testing/test_app'),
entryPoint: 'lib/benchmarks/runner.dart',
useCanvasKit: false,
treeShakeIcons: false,
);

for (final String benchmarkName in <String>['scroll', 'page', 'tap']) {
Expand Down