Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a benchmark for ImageCache #33814

Merged
merged 3 commits into from Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions dev/benchmarks/complex_layout/pubspec.yaml
Expand Up @@ -15,7 +15,7 @@ dependencies:
# //packages/flutter_tools/lib/src/commands/update_packages.dart
# and run
# flutter update-packages --force-upgrade
flutter_gallery_assets: 0.1.8
flutter_gallery_assets: 0.1.9+2

async: 2.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
charcode: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
Expand Down Expand Up @@ -82,4 +82,4 @@ flutter:
- packages/flutter_gallery_assets/people/square/ali.png
- packages/flutter_gallery_assets/places/india_chettinad_silk_maker.png

# PUBSPEC CHECKSUM: f69a
# PUBSPEC CHECKSUM: e4f8
4 changes: 2 additions & 2 deletions dev/benchmarks/macrobenchmarks/pubspec.yaml
Expand Up @@ -15,7 +15,7 @@ dependencies:
# //packages/flutter_tools/lib/src/commands/update_packages.dart
# and run
# flutter update-packages --force-upgrade
flutter_gallery_assets: 0.1.8
flutter_gallery_assets: 0.1.9+2

async: 2.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
charcode: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
Expand Down Expand Up @@ -79,4 +79,4 @@ dev_dependencies:
flutter:
uses-material-design: true

# PUBSPEC CHECKSUM: f69a
# PUBSPEC CHECKSUM: e4f8
17 changes: 17 additions & 0 deletions dev/devicelab/bin/tasks/flutter_gallery__image_cache_memory.dart
@@ -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);
}
7 changes: 7 additions & 0 deletions dev/devicelab/manifest.yaml
Expand Up @@ -528,6 +528,13 @@ tasks:
required_agent_capabilities: ["linux/android"]
flaky: true

flutter_gallery__image_cache_memory:
description: >
Measures memory usage for a list of large red squares in smaller containers.
stage: devicelab
required_agent_capabilities: ["linux/android"]
flaky: true

analyzer_benchmark:
description: >
Measures the speed of Dart analyzer.
Expand Down
5 changes: 3 additions & 2 deletions examples/flutter_gallery/pubspec.yaml
Expand Up @@ -19,7 +19,7 @@ dependencies:
shrine_images: 1.1.2

# Also update dev/benchmarks/complex_layout/pubspec.yaml
flutter_gallery_assets: 0.1.8
flutter_gallery_assets: 0.1.9+2

charcode: 1.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
meta: 1.1.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
Expand Down Expand Up @@ -88,6 +88,7 @@ flutter:
assets:
- lib/gallery/example_code.dart
- packages/flutter_gallery_assets/people/ali_landscape.png
- packages/flutter_gallery_assets/monochrome/red-square-1024x1024.png
- packages/flutter_gallery_assets/logos/flutter_white/logo.png
- packages/flutter_gallery_assets/logos/fortnightly/fortnightly_logo.png
- packages/flutter_gallery_assets/videos/bee.mp4
Expand Down Expand Up @@ -253,4 +254,4 @@ flutter:
- asset: packages/flutter_gallery_assets/fonts/merriweather/Merriweather-Regular.ttf
- asset: packages/flutter_gallery_assets/fonts/merriweather/Merriweather-Light.ttf

# PUBSPEC CHECKSUM: 7863
# PUBSPEC CHECKSUM: 35c1
63 changes: 63 additions & 0 deletions examples/flutter_gallery/test_memory/image_cache_memory.dart
@@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this waiting for the GPU thread to rasterize the frame? If so, please add a comment here because this is potentially a flaky test. We should change it once we had more reliable mechanism (e.g., Window.onReportTimings in flutter/engine#8983).

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 ====');
}
Expand Up @@ -21,7 +21,7 @@ import '../runner/flutter_command.dart';
/// package version in cases when upgrading to the latest breaks Flutter.
const Map<String, String> _kManuallyPinnedDependencies = <String, String>{
// Add pinned packages here.
'flutter_gallery_assets': '0.1.8', // See //examples/flutter_gallery/pubspec.yaml
'flutter_gallery_assets': '0.1.9+2', // See //examples/flutter_gallery/pubspec.yaml
'build_daemon': '0.6.1', // Crashes at 1.0
'test': '1.6.3', // | Tests are timing out at 1.6.4 https://github.com/flutter/flutter/issues/33823
'test_api': '0.2.5', // |
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_tools/pubspec.yaml
Expand Up @@ -19,7 +19,7 @@ dependencies:
http: 0.12.0+2
intl: 0.15.8
json_rpc_2: 2.1.0
linter: 0.1.90
linter: 0.1.91
meta: 1.1.6
multicast_dns: 0.1.1
mustache: 1.1.1
Expand Down Expand Up @@ -119,4 +119,4 @@ dartdoc:
# Exclude this package from the hosted API docs.
nodoc: true

# PUBSPEC CHECKSUM: ef94
# PUBSPEC CHECKSUM: bf95