benchmark memory usage for grid view of memory intensive widgets (#61025)
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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(),
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
32
dev/benchmarks/macrobenchmarks/lib/src/heavy_grid_view.dart
Normal file
32
dev/benchmarks/macrobenchmarks/lib/src/heavy_grid_view.dart
Normal file
@@ -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}'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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 ====');
|
||||
}
|
||||
Reference in New Issue
Block a user