forked from flutter/flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark memory usage for grid view of memory intensive widgets (flu…
- Loading branch information
1 parent
33334f7
commit 6ade392
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
dev/benchmarks/macrobenchmarks/lib/src/heavy_grid_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
dev/benchmarks/macrobenchmarks/test_memory/heavy_gridview.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
dev/devicelab/bin/tasks/fast_scroll_heavy_gridview__memory.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters