Skip to content

Commit 6ade392

Browse files
dnfieldmingwandroid
authored andcommitted
benchmark memory usage for grid view of memory intensive widgets (flutter#61025)
1 parent 33334f7 commit 6ade392

File tree

6 files changed

+119
-0
lines changed

6 files changed

+119
-0
lines changed

dev/benchmarks/macrobenchmarks/lib/common.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ const String kColorFilterAndFadeRouteName = '/color_filter_and_fade';
1515
const String kFadingChildAnimationRouteName = '/fading_child_animation';
1616
const String kImageFilteredTransformAnimationRouteName = '/imagefiltered_transform_animation';
1717
const String kMultiWidgetConstructionRouteName = '/multi_widget_construction';
18+
const String kHeavyGridViewRouteName = '/heavy_gridview';
1819

1920
const String kScrollableName = '/macrobenchmark_listview';

dev/benchmarks/macrobenchmarks/lib/main.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:flutter/material.dart';
66
import 'package:macrobenchmarks/src/color_filter_and_fade.dart';
7+
import 'package:macrobenchmarks/src/heavy_grid_view.dart';
78
import 'package:macrobenchmarks/src/large_images.dart';
89
import 'package:macrobenchmarks/src/picture_cache.dart';
910

@@ -45,6 +46,7 @@ class MacrobenchmarksApp extends StatelessWidget {
4546
kFadingChildAnimationRouteName: (BuildContext context) => const FilteredChildAnimationPage(FilterType.opacity),
4647
kImageFilteredTransformAnimationRouteName: (BuildContext context) => const FilteredChildAnimationPage(FilterType.rotateFilter),
4748
kMultiWidgetConstructionRouteName: (BuildContext context) => const MultiWidgetConstructTable(10, 20),
49+
kHeavyGridViewRouteName: (BuildContext context) => HeavyGridViewPage(),
4850
},
4951
);
5052
}
@@ -151,6 +153,13 @@ class HomePage extends StatelessWidget {
151153
Navigator.pushNamed(context, kMultiWidgetConstructionRouteName);
152154
},
153155
),
156+
RaisedButton(
157+
key: const Key(kHeavyGridViewRouteName),
158+
child: const Text('Heavy Grid View'),
159+
onPressed: () {
160+
Navigator.pushNamed(context, kHeavyGridViewRouteName);
161+
},
162+
),
154163
],
155164
),
156165
);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2014 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 HeavyGridViewPage extends StatelessWidget {
8+
@override
9+
Widget build(BuildContext context) {
10+
return GridView.builder(
11+
itemCount: 1000,
12+
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
13+
itemBuilder: (BuildContext context, int index) => HeavyWidget(index),
14+
).build(context);
15+
}
16+
}
17+
18+
class HeavyWidget extends StatelessWidget {
19+
HeavyWidget(this.index) : super(key: ValueKey<int>(index));
20+
21+
final int index;
22+
final List<int> _weight = List<int>(1000000);
23+
24+
@override
25+
Widget build(BuildContext context) {
26+
return SizedBox(
27+
width: 200,
28+
height: 200,
29+
child: Text('$index: ${_weight.length}'),
30+
);
31+
}
32+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 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 'dart:async';
6+
7+
import 'package:flutter/material.dart';
8+
import 'package:flutter/scheduler.dart';
9+
import 'package:flutter_test/flutter_test.dart';
10+
import 'package:macrobenchmarks/common.dart';
11+
import 'package:macrobenchmarks/main.dart';
12+
13+
Future<void> endOfAnimation() async {
14+
do {
15+
await SchedulerBinding.instance.endOfFrame;
16+
} while (SchedulerBinding.instance.hasScheduledFrame);
17+
}
18+
19+
Future<void> main() async {
20+
runApp(const MacrobenchmarksApp(initialRoute: kHeavyGridViewRouteName));
21+
await endOfAnimation();
22+
await Future<void>.delayed(const Duration(milliseconds: 50));
23+
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
24+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2014 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 'dart:async';
6+
7+
import 'package:flutter_devicelab/framework/adb.dart';
8+
import 'package:flutter_devicelab/framework/framework.dart';
9+
import 'package:flutter_devicelab/framework/utils.dart';
10+
import 'package:flutter_devicelab/tasks/perf_tests.dart';
11+
12+
const String kPackageName = 'com.example.macrobenchmarks';
13+
const String kActivityName = 'com.example.macrobenchmarks.MainActivity';
14+
15+
class FastScrollHeavyGridViewMemoryTest extends MemoryTest {
16+
FastScrollHeavyGridViewMemoryTest()
17+
: super(
18+
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
19+
'test_memory/heavy_gridview.dart', kPackageName,
20+
);
21+
22+
@override
23+
AndroidDevice get device => super.device as AndroidDevice;
24+
25+
@override
26+
int get iterationCount => 5;
27+
28+
@override
29+
Future<void> useMemory() async {
30+
await launchApp();
31+
await recordStart();
32+
await device.shellExec('input', <String>['swipe', '50 1500 50 50 50']);
33+
await Future<void>.delayed(const Duration(milliseconds: 1500));
34+
await device.shellExec('input', <String>['swipe', '50 1500 50 50 50']);
35+
await Future<void>.delayed(const Duration(milliseconds: 1500));
36+
await device.shellExec('input', <String>['swipe', '50 1500 50 50 50']);
37+
await Future<void>.delayed(const Duration(milliseconds: 1500));
38+
await recordEnd();
39+
}
40+
}
41+
42+
Future<void> main() async {
43+
deviceOperatingSystem = DeviceOperatingSystem.android;
44+
await task(FastScrollHeavyGridViewMemoryTest().run);
45+
}

dev/devicelab/manifest.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,14 @@ tasks:
803803
stage: devicelab
804804
required_agent_capabilities: ["mac/android"]
805805

806+
fast_scroll_heavy_gridview__memory:
807+
description: >
808+
Measures memory usage for scrolling through a grid view of heavy memory
809+
usage widgets.
810+
stage: devicelab
811+
required_agent_capabilities: ["linux/android"]
812+
flaky: true
813+
806814
animated_placeholder_perf:
807815
description: >
808816
Measures frame build and rasterizer times, as well as frame build counts

0 commit comments

Comments
 (0)