Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a benchmark for ImageCache (#33814)
* Add an image cache benchmark for a monochrome image
- Loading branch information
1 parent
e0cb468
commit 92bfc99
Showing
8 changed files
with
97 additions
and
9 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
17 changes: 17 additions & 0 deletions
17
dev/devicelab/bin/tasks/flutter_gallery__image_cache_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,17 @@ | ||
// Copyright 2016 The Chromium 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/framework.dart'; | ||
import 'package:flutter_devicelab/framework/utils.dart'; | ||
import 'package:flutter_devicelab/tasks/perf_tests.dart'; | ||
|
||
Future<void> main() async { | ||
await task(MemoryTest( | ||
'${flutterDirectory.path}/examples/flutter_gallery', | ||
'test_memory/image_cache_memory.dart', | ||
'io.flutter.demo.gallery', | ||
).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
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
63 changes: 63 additions & 0 deletions
63
examples/flutter_gallery/test_memory/image_cache_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,63 @@ | ||
// Copyright 2016 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// See //dev/devicelab/bin/tasks/flutter_gallery__image_cache_memory.dart | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter/scheduler.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
// Once we provide an option for images to be resized to | ||
// fit the container, we should see a significant drop in | ||
// the amount of memory consumed by this benchmark. | ||
Future<void> main() async { | ||
const int numItems = 10; | ||
|
||
runApp(Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: ListView.builder( | ||
key: const Key('ImageList'), | ||
itemCount: numItems, | ||
itemBuilder: (BuildContext context, int position) { | ||
return Container( | ||
width: 200, | ||
height: 200, | ||
child: Center( | ||
child: Image.asset( | ||
'monochrome/red-square-1024x1024.png', | ||
package: 'flutter_gallery_assets', | ||
width: 100, | ||
height: 100, | ||
fit: BoxFit.contain, | ||
key: Key('image_$position'), | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
)); | ||
|
||
await SchedulerBinding.instance.endOfFrame; | ||
|
||
// We are waiting for the GPU to rasterize a frame here. This makes this flaky, | ||
// we can rely on a more deterministic such as `Window.onReportTimings` once | ||
// https://github.com/flutter/flutter/issues/26154 is addressed. | ||
await Future<void>.delayed(const Duration(milliseconds: 50)); | ||
debugPrint('==== MEMORY BENCHMARK ==== READY ===='); | ||
|
||
final WidgetController controller = | ||
LiveWidgetController(WidgetsBinding.instance); | ||
|
||
debugPrint('Scrolling...'); | ||
final Finder list = find.byKey(const Key('ImageList')); | ||
final Finder lastItem = find.byKey(const Key('image_${numItems - 1}')); | ||
do { | ||
await controller.drag(list, const Offset(0.0, -30.0)); | ||
await Future<void>.delayed(const Duration(milliseconds: 20)); | ||
} while (!lastItem.precache()); | ||
|
||
debugPrint('==== MEMORY BENCHMARK ==== DONE ===='); | ||
} |
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