mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Memory test on scrolling large images quickly (#46184)
This commit is contained in:
parent
42cb9190b2
commit
a2005eaf9a
BIN
dev/benchmarks/macrobenchmarks/assets/999x1000.png
Normal file
BIN
dev/benchmarks/macrobenchmarks/assets/999x1000.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
@ -7,3 +7,4 @@ const String kCubicBezierRouteName = '/cubic_bezier';
|
|||||||
const String kBackdropFilterRouteName = '/backdrop_filter';
|
const String kBackdropFilterRouteName = '/backdrop_filter';
|
||||||
const String kSimpleAnimationRouteName = '/simple_animation';
|
const String kSimpleAnimationRouteName = '/simple_animation';
|
||||||
const String kPictureCacheRouteName = '/picture_cache';
|
const String kPictureCacheRouteName = '/picture_cache';
|
||||||
|
const String kLargeImagesRouteName = '/large_images';
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:macrobenchmarks/src/large_images.dart';
|
||||||
import 'package:macrobenchmarks/src/picture_cache.dart';
|
import 'package:macrobenchmarks/src/picture_cache.dart';
|
||||||
|
|
||||||
import 'common.dart';
|
import 'common.dart';
|
||||||
@ -13,24 +14,29 @@ import 'src/simple_animation.dart';
|
|||||||
|
|
||||||
const String kMacrobenchmarks ='Macrobenchmarks';
|
const String kMacrobenchmarks ='Macrobenchmarks';
|
||||||
|
|
||||||
void main() => runApp(MacrobenchmarksApp());
|
void main() => runApp(const MacrobenchmarksApp());
|
||||||
|
|
||||||
class MacrobenchmarksApp extends StatelessWidget {
|
class MacrobenchmarksApp extends StatelessWidget {
|
||||||
|
const MacrobenchmarksApp({this.initialRoute = '/'});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: kMacrobenchmarks,
|
title: kMacrobenchmarks,
|
||||||
initialRoute: '/',
|
initialRoute: initialRoute,
|
||||||
routes: <String, WidgetBuilder>{
|
routes: <String, WidgetBuilder>{
|
||||||
'/': (BuildContext context) => HomePage(),
|
'/': (BuildContext context) => HomePage(),
|
||||||
kCullOpacityRouteName: (BuildContext context) => CullOpacityPage(),
|
kCullOpacityRouteName: (BuildContext context) => CullOpacityPage(),
|
||||||
kCubicBezierRouteName: (BuildContext context) => CubicBezierPage(),
|
kCubicBezierRouteName: (BuildContext context) => CubicBezierPage(),
|
||||||
kBackdropFilterRouteName: (BuildContext context) => BackdropFilterPage(),
|
kBackdropFilterRouteName: (BuildContext context) => BackdropFilterPage(),
|
||||||
kSimpleAnimationRouteName: (BuildContext conttext) => SimpleAnimationPage(),
|
kSimpleAnimationRouteName: (BuildContext conttext) => SimpleAnimationPage(),
|
||||||
kPictureCacheRouteName: (BuildContext conttext) => PictureCachePage(),
|
kPictureCacheRouteName: (BuildContext context) => PictureCachePage(),
|
||||||
|
kLargeImagesRouteName: (BuildContext context) => LargeImagesPage(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final String initialRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
class HomePage extends StatelessWidget {
|
class HomePage extends StatelessWidget {
|
||||||
@ -75,6 +81,13 @@ class HomePage extends StatelessWidget {
|
|||||||
Navigator.pushNamed(context, kPictureCacheRouteName);
|
Navigator.pushNamed(context, kPictureCacheRouteName);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
RaisedButton(
|
||||||
|
key: const Key(kLargeImagesRouteName),
|
||||||
|
child: const Text('Large Images'),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pushNamed(context, kLargeImagesRouteName);
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
48
dev/benchmarks/macrobenchmarks/lib/src/large_images.dart
Normal file
48
dev/benchmarks/macrobenchmarks/lib/src/large_images.dart
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// 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 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class LargeImagesPage extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final ImageCache imageCache = PaintingBinding.instance.imageCache;
|
||||||
|
imageCache.maximumSize = 30;
|
||||||
|
imageCache.maximumSizeBytes = 50 << 20;
|
||||||
|
return GridView.builder(
|
||||||
|
itemCount: 1000,
|
||||||
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
|
||||||
|
itemBuilder: (BuildContext context, int index) => DummyImage(index),
|
||||||
|
).build(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DummyImage extends StatelessWidget {
|
||||||
|
DummyImage(this.index) : super(key: ValueKey<int>(index));
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final Future<ByteData> pngData = _getPngData(context);
|
||||||
|
|
||||||
|
return FutureBuilder<ByteData>(
|
||||||
|
future: pngData,
|
||||||
|
builder: (BuildContext context, AsyncSnapshot<ByteData> snapshot) {
|
||||||
|
// Use Image.memory instead of Image.asset to make sure that we're
|
||||||
|
// creating many copies of the image to trigger the memory issue.
|
||||||
|
return snapshot.data == null
|
||||||
|
? Container()
|
||||||
|
: Image.memory(snapshot.data.buffer.asUint8List());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final int index;
|
||||||
|
|
||||||
|
Future<ByteData> _getPngData(BuildContext context) async {
|
||||||
|
return DefaultAssetBundle.of(context).load('assets/999x1000.png');
|
||||||
|
}
|
||||||
|
}
|
@ -90,5 +90,6 @@ flutter:
|
|||||||
assets:
|
assets:
|
||||||
- packages/flutter_gallery_assets/food/butternut_squash_soup.png
|
- packages/flutter_gallery_assets/food/butternut_squash_soup.png
|
||||||
- packages/flutter_gallery_assets/food/cherry_pie.png
|
- packages/flutter_gallery_assets/food/cherry_pie.png
|
||||||
|
- assets/999x1000.png
|
||||||
|
|
||||||
# PUBSPEC CHECKSUM: 4cef
|
# PUBSPEC CHECKSUM: 4cef
|
||||||
|
35
dev/benchmarks/macrobenchmarks/test_memory/large_images.dart
Normal file
35
dev/benchmarks/macrobenchmarks/test_memory/large_images.dart
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
int iteration = 0;
|
||||||
|
|
||||||
|
class LifecycleObserver extends WidgetsBindingObserver {
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
debugPrint('==== MEMORY BENCHMARK ==== $state ====');
|
||||||
|
debugPrint('This was lifecycle event number $iteration in this instance');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
runApp(const MacrobenchmarksApp(initialRoute: kLargeImagesRouteName));
|
||||||
|
await endOfAnimation();
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||||
|
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
|
||||||
|
WidgetsBinding.instance.addObserver(LifecycleObserver());
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
// 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 FastScrollLargeImagesMemoryTest extends MemoryTest {
|
||||||
|
FastScrollLargeImagesMemoryTest()
|
||||||
|
: super(
|
||||||
|
'${flutterDirectory.path}/dev/benchmarks/macrobenchmarks',
|
||||||
|
'test_memory/large_images.dart', kPackageName,
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
AndroidDevice get device => super.device;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get iterationCount => 5;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> useMemory() async {
|
||||||
|
await launchApp();
|
||||||
|
await recordStart();
|
||||||
|
await device.shellExec('input', <String>['swipe', '0 1500 0 0 50']);
|
||||||
|
await Future<void>.delayed(const Duration(milliseconds: 10000));
|
||||||
|
await recordEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> main() async {
|
||||||
|
deviceOperatingSystem = DeviceOperatingSystem.android;
|
||||||
|
await task(FastScrollLargeImagesMemoryTest().run);
|
||||||
|
}
|
@ -670,6 +670,12 @@ tasks:
|
|||||||
stage: devicelab
|
stage: devicelab
|
||||||
required_agent_capabilities: ["linux/android"]
|
required_agent_capabilities: ["linux/android"]
|
||||||
|
|
||||||
|
fast_scroll_large_images__memory:
|
||||||
|
description: >
|
||||||
|
Measures memory usage for scrolling through a list of large images.
|
||||||
|
stage: devicelab
|
||||||
|
required_agent_capabilities: ["mac/android"]
|
||||||
|
|
||||||
analyzer_benchmark:
|
analyzer_benchmark:
|
||||||
description: >
|
description: >
|
||||||
Measures the speed of Dart analyzer.
|
Measures the speed of Dart analyzer.
|
||||||
|
Loading…
Reference in New Issue
Block a user