Skip to content

Commit

Permalink
benchmark memory usage for grid view of memory intensive widgets (flu…
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored and mingwandroid committed Sep 6, 2020
1 parent 33334f7 commit 6ade392
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev/benchmarks/macrobenchmarks/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ const String kColorFilterAndFadeRouteName = '/color_filter_and_fade';
const String kFadingChildAnimationRouteName = '/fading_child_animation';
const String kImageFilteredTransformAnimationRouteName = '/imagefiltered_transform_animation';
const String kMultiWidgetConstructionRouteName = '/multi_widget_construction';
const String kHeavyGridViewRouteName = '/heavy_gridview';

const String kScrollableName = '/macrobenchmark_listview';
9 changes: 9 additions & 0 deletions dev/benchmarks/macrobenchmarks/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:flutter/material.dart';
import 'package:macrobenchmarks/src/color_filter_and_fade.dart';
import 'package:macrobenchmarks/src/heavy_grid_view.dart';
import 'package:macrobenchmarks/src/large_images.dart';
import 'package:macrobenchmarks/src/picture_cache.dart';

Expand Down Expand Up @@ -45,6 +46,7 @@ class MacrobenchmarksApp extends StatelessWidget {
kFadingChildAnimationRouteName: (BuildContext context) => const FilteredChildAnimationPage(FilterType.opacity),
kImageFilteredTransformAnimationRouteName: (BuildContext context) => const FilteredChildAnimationPage(FilterType.rotateFilter),
kMultiWidgetConstructionRouteName: (BuildContext context) => const MultiWidgetConstructTable(10, 20),
kHeavyGridViewRouteName: (BuildContext context) => HeavyGridViewPage(),
},
);
}
Expand Down Expand Up @@ -151,6 +153,13 @@ class HomePage extends StatelessWidget {
Navigator.pushNamed(context, kMultiWidgetConstructionRouteName);
},
),
RaisedButton(
key: const Key(kHeavyGridViewRouteName),
child: const Text('Heavy Grid View'),
onPressed: () {
Navigator.pushNamed(context, kHeavyGridViewRouteName);
},
),
],
),
);
Expand Down
32 changes: 32 additions & 0 deletions dev/benchmarks/macrobenchmarks/lib/src/heavy_grid_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2014 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 HeavyGridViewPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GridView.builder(
itemCount: 1000,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (BuildContext context, int index) => HeavyWidget(index),
).build(context);
}
}

class HeavyWidget extends StatelessWidget {
HeavyWidget(this.index) : super(key: ValueKey<int>(index));

final int index;
final List<int> _weight = List<int>(1000000);

@override
Widget build(BuildContext context) {
return SizedBox(
width: 200,
height: 200,
child: Text('$index: ${_weight.length}'),
);
}
}
24 changes: 24 additions & 0 deletions dev/benchmarks/macrobenchmarks/test_memory/heavy_gridview.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2014 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 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:macrobenchmarks/common.dart';
import 'package:macrobenchmarks/main.dart';

Future<void> endOfAnimation() async {
do {
await SchedulerBinding.instance.endOfFrame;
} while (SchedulerBinding.instance.hasScheduledFrame);
}

Future<void> main() async {
runApp(const MacrobenchmarksApp(initialRoute: kHeavyGridViewRouteName));
await endOfAnimation();
await Future<void>.delayed(const Duration(milliseconds: 50));
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
}
45 changes: 45 additions & 0 deletions dev/devicelab/bin/tasks/fast_scroll_heavy_gridview__memory.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2014 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 'dart:async';

import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart';
import 'package:flutter_devicelab/tasks/perf_tests.dart';

const String kPackageName = 'com.example.macrobenchmarks';
const String kActivityName = 'com.example.macrobenchmarks.MainActivity';

class FastScrollHeavyGridViewMemoryTest extends MemoryTest {
FastScrollHeavyGridViewMemoryTest()
: super(
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
'test_memory/heavy_gridview.dart', kPackageName,
);

@override
AndroidDevice get device => super.device as AndroidDevice;

@override
int get iterationCount => 5;

@override
Future<void> useMemory() async {
await launchApp();
await recordStart();
await device.shellExec('input', <String>['swipe', '50 1500 50 50 50']);
await Future<void>.delayed(const Duration(milliseconds: 1500));
await device.shellExec('input', <String>['swipe', '50 1500 50 50 50']);
await Future<void>.delayed(const Duration(milliseconds: 1500));
await device.shellExec('input', <String>['swipe', '50 1500 50 50 50']);
await Future<void>.delayed(const Duration(milliseconds: 1500));
await recordEnd();
}
}

Future<void> main() async {
deviceOperatingSystem = DeviceOperatingSystem.android;
await task(FastScrollHeavyGridViewMemoryTest().run);
}
8 changes: 8 additions & 0 deletions dev/devicelab/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,14 @@ tasks:
stage: devicelab
required_agent_capabilities: ["mac/android"]

fast_scroll_heavy_gridview__memory:
description: >
Measures memory usage for scrolling through a grid view of heavy memory
usage widgets.
stage: devicelab
required_agent_capabilities: ["linux/android"]
flaky: true

animated_placeholder_perf:
description: >
Measures frame build and rasterizer times, as well as frame build counts
Expand Down

0 comments on commit 6ade392

Please sign in to comment.