Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bae7959

Browse files
authoredFeb 28, 2020
add docs about writing/running web benchmarks (flutter#50989)
* add docs about writing/running web benchmarks * explain how to run like devicelab * add WidgetBuildRecorder docs
1 parent cd0fbd3 commit bae7959

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed
 

‎dev/benchmarks/macrobenchmarks/README.md

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Macrobenchmarks
22

3-
Performance benchmarks using flutter drive.
3+
Performance benchmarks use either flutter drive or the web benchmark harness.
44

5-
## Cull opacity benchmark
5+
## Mobile benchmarks
6+
7+
### Cull opacity benchmark
68

79
To run the cull opacity benchmark on a device:
810

@@ -14,7 +16,7 @@ Results should be in the file `build/cull_opacity_perf.timeline_summary.json`.
1416

1517
More detailed logs should be in `build/cull_opacity_perf.timeline.json`.
1618

17-
## Cubic bezier benchmark
19+
### Cubic bezier benchmark
1820

1921
To run the cubic bezier benchmark on a device:
2022

@@ -26,7 +28,7 @@ Results should be in the file `build/cubic_bezier_perf.timeline_summary.json`.
2628

2729
More detailed logs should be in `build/cubic_bezier_perf.timeline.json`.
2830

29-
## Backdrop filter benchmark
31+
### Backdrop filter benchmark
3032

3133
To run the backdrop filter benchmark on a device:
3234

@@ -38,7 +40,7 @@ Results should be in the file `build/backdrop_filter_perf.timeline_summary.json`
3840

3941
More detailed logs should be in `build/backdrop_filter_perf.timeline.json`.
4042

41-
## Post Backdrop filter benchmark
43+
### Post Backdrop filter benchmark
4244

4345
To run the post-backdrop filter benchmark on a device:
4446

@@ -49,3 +51,70 @@ flutter drive --profile test_driver/post_backdrop_filter_perf.dart
4951
Results should be in the file `build/post_backdrop_filter_perf.timeline_summary.json`.
5052

5153
More detailed logs should be in `build/post_backdrop_filter_perf.timeline.json`.
54+
55+
## Web benchmarks
56+
57+
Web benchmarks are compiled from the same entrypoint in `lib/web_benchmarks.dart`.
58+
59+
### How to write a web benchmark
60+
61+
Create a new file for your benchmark under `lib/src/web`. See `bench_draw_rect.dart`
62+
as an example.
63+
64+
Choose one of the two benchmark types:
65+
66+
* A "raw benchmark" records performance metrics from direct interactions with
67+
`dart:ui` with no framework. This kind of benchmark is good for benchmarking
68+
low-level engine primitives, such as layer, picture, and semantics performance.
69+
* A "widget benchmark" records performance metrics using a widget. This kind of
70+
benchmark is good for measuring the performance of widgets, often together with
71+
engine work that widget-under-test incurs.
72+
* A "widget build benchmark" records the cost of building a widget from nothing.
73+
This is different from the "widget benchmark" because typically the latter
74+
only performs incremental UI updates, such as an animation. In contrast, this
75+
benchmark pumps an empty frame to clear all previously built widgets and
76+
rebuilds them from scratch.
77+
78+
For a raw benchmark extend `RawRecorder` (tip: you can start by copying
79+
`bench_draw_rect.dart`).
80+
81+
For a widget benchmark extend `WidgetRecorder` (tip: you can start by copying
82+
`bench_simple_lazy_text_scroll.dart`).
83+
84+
For a widget build benchmark extend `WidgetBuildRecorder` (tip: you can start by copying
85+
`bench_build_material_checkbox.dart`).
86+
87+
Pick a unique benchmark name and class name and add it to the `benchmarks` list
88+
in `lib/web_benchmarks.dart`.
89+
90+
### How to run a web benchmark
91+
92+
Web benchmarks can be run using `flutter run` in debug, profile, and release
93+
modes, using either the HTML or the CanvasKit rendering backend. Note, however,
94+
that running in debug mode will result in worse numbers. Profile mode is useful
95+
for profiling in Chrome DevTools because the numbers are close to release mode
96+
and the profile contains unobfuscated names.
97+
98+
Example:
99+
100+
```
101+
cd dev/benchmarks/macrobenchmarks
102+
103+
# Runs in profile mode using the HTML renderer
104+
flutter run --profile -d web-server lib/web_benchmarks.dart
105+
106+
# Runs in profile mode using the CanvasKit renderer
107+
flutter run --dart-define=FLUTTER_WEB_USE_SKIA=true --profile -d web-server lib/web_benchmarks.dart
108+
```
109+
110+
You can also run all benchmarks exactly like the devicelab runs them:
111+
112+
```
113+
cd dev/devicelab
114+
115+
# Runs using the HTML renderer
116+
../../bin/cache/dart-sdk/bin/dart bin/run.dart -t bin/tasks/web_benchmarks_html.dart
117+
118+
# Runs using the CanvasKit renderer
119+
../../bin/cache/dart-sdk/bin/dart bin/run.dart -t bin/tasks/web_benchmarks_canvaskit.dart
120+
```

‎dev/benchmarks/macrobenchmarks/lib/web_benchmarks.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import 'src/web/recorder.dart';
1717

1818
typedef RecorderFactory = Recorder Function();
1919

20+
/// List of all benchmarks that run in the devicelab.
21+
///
22+
/// When adding a new benchmark, add it to this map. Make sure that the name
23+
/// of your benchmark is unique.
2024
final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
2125
BenchCardInfiniteScroll.benchmarkName: () => BenchCardInfiniteScroll(),
2226
BenchDrawRect.benchmarkName: () => BenchDrawRect(),

0 commit comments

Comments
 (0)