Skip to content

Commit 2807d05

Browse files
Add '--no-tree-shake-icons' option to BenchmarkServer (flutter#5186)
1 parent a673198 commit 2807d05

File tree

11 files changed

+68
-7
lines changed

11 files changed

+68
-7
lines changed

packages/web_benchmarks/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.1.0+8
2+
3+
* Adds an optional parameter `treeShakeIcons` to `serveWebBenchmark`.
4+
* Adds a required and named parameter `treeShakeIcons` to `BenchmarkServer`.
5+
16
## 0.1.0+7
27

38
* Updates `package:process` version constraints.

packages/web_benchmarks/lib/server.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Future<BenchmarkResults> serveWebBenchmark({
4646
int benchmarkServerPort = defaultBenchmarkServerPort,
4747
int chromeDebugPort = defaultChromeDebugPort,
4848
bool headless = true,
49+
bool treeShakeIcons = true,
4950
}) async {
5051
// Reduce logging level. Otherwise, package:webkit_inspection_protocol is way too spammy.
5152
Logger.root.level = Level.INFO;
@@ -57,5 +58,6 @@ Future<BenchmarkResults> serveWebBenchmark({
5758
benchmarkServerPort: benchmarkServerPort,
5859
chromeDebugPort: chromeDebugPort,
5960
headless: headless,
61+
treeShakeIcons: treeShakeIcons,
6062
).run();
6163
}

packages/web_benchmarks/lib/src/runner.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class BenchmarkServer {
5454
required this.benchmarkServerPort,
5555
required this.chromeDebugPort,
5656
required this.headless,
57+
required this.treeShakeIcons,
5758
});
5859

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

88+
/// Whether to tree shake icons during the build.
89+
///
90+
/// When false, '--no-tree-shake-icons' will be passed as a build argument.
91+
final bool treeShakeIcons;
92+
8793
/// Builds and serves the benchmark app, and collects benchmark results.
8894
Future<BenchmarkResults> run() async {
8995
// Reduce logging level. Otherwise, package:webkit_inspection_protocol is way too spammy.
@@ -101,6 +107,7 @@ class BenchmarkServer {
101107
'web',
102108
'--dart-define=FLUTTER_WEB_ENABLE_PROFILING=true',
103109
if (useCanvasKit) '--dart-define=FLUTTER_WEB_USE_SKIA=true',
110+
if (!treeShakeIcons) '--no-tree-shake-icons',
104111
'--profile',
105112
'-t',
106113
entryPoint,

packages/web_benchmarks/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: web_benchmarks
22
description: A benchmark harness for performance-testing Flutter apps in Chrome.
33
repository: https://github.com/flutter/packages/tree/main/packages/web_benchmarks
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+web_benchmarks%22
5-
version: 0.1.0+7
5+
version: 0.1.0+8
66

77
environment:
88
sdk: ">=2.19.0 <4.0.0"

packages/web_benchmarks/testing/test_app/lib/benchmarks/runner.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import 'package:flutter/material.dart';
88
import 'package:flutter_test/flutter_test.dart';
99
import 'package:web_benchmarks/client.dart';
1010

11-
import '../aboutpage.dart' show backKey;
12-
import '../homepage.dart' show aboutPageKey, textKey;
11+
import '../about_page.dart' show backKey;
12+
import '../home_page.dart' show aboutPageKey, textKey;
1313
import '../main.dart';
1414

1515
/// A recorder that measures frame building durations.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
class IconGeneratorPage extends StatefulWidget {
8+
const IconGeneratorPage({super.key});
9+
10+
static int defaultIconCodePoint = int.parse('0xf03f');
11+
12+
@override
13+
State<IconGeneratorPage> createState() => _IconGeneratorPageState();
14+
}
15+
16+
class _IconGeneratorPageState extends State<IconGeneratorPage> {
17+
int iconCodePoint = IconGeneratorPage.defaultIconCodePoint;
18+
19+
@override
20+
Widget build(BuildContext context) {
21+
return Column(
22+
children: <Widget>[
23+
TextField(
24+
onSubmitted: (String value) {
25+
final int codePointAsInt =
26+
int.tryParse(value) ?? IconGeneratorPage.defaultIconCodePoint;
27+
setState(() {
28+
iconCodePoint = codePointAsInt;
29+
});
30+
},
31+
),
32+
const SizedBox(height: 24.0),
33+
Icon(generateIcon(iconCodePoint)),
34+
],
35+
);
36+
}
37+
38+
// Unless '--no-tree-shake-icons' is passed to the flutter build command,
39+
// the presence of this method will trigger an exception due to the use of
40+
// non-constant invocations of [IconData].
41+
IconData generateIcon(int materialIconCodePoint) => IconData(
42+
materialIconCodePoint,
43+
fontFamily: 'MaterialIcons',
44+
);
45+
}

packages/web_benchmarks/testing/test_app/lib/main.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import 'package:flutter/material.dart';
66

7-
import 'aboutpage.dart';
8-
import 'homepage.dart';
7+
import 'about_page.dart';
8+
import 'home_page.dart';
9+
import 'icon_page.dart';
910

1011
void main() {
1112
runApp(const MyApp());
@@ -26,6 +27,7 @@ class MyApp extends StatelessWidget {
2627
routes: <String, WidgetBuilder>{
2728
'home': (_) => const HomePage(title: 'Flutter Demo Home Page'),
2829
'about': (_) => const AboutPage(),
30+
'icon_generator': (_) => const IconGeneratorPage(),
2931
},
3032
);
3133
}

packages/web_benchmarks/testing/test_app/pubspec.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ publish_to: 'none'
66
version: 1.0.0+1
77

88
environment:
9-
sdk: ">=2.19.0 <4.0.0"
9+
sdk: '>=2.19.0 <4.0.0'
1010

1111
dependencies:
12-
cupertino_icons: ^1.0.5
1312
flutter:
1413
sdk: flutter
1514
flutter_test:

0 commit comments

Comments
 (0)