From d030296a97f79483d63942e642816e153e38de70 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 20 Feb 2020 01:51:15 -0800 Subject: [PATCH] Reland test (#50987) --- .../macrobenchmarks/lib/common.dart | 1 + dev/benchmarks/macrobenchmarks/lib/main.dart | 11 ++- .../lib/src/animated_placeholder.dart | 68 +++++++++++++++++++ .../animated_placeholder_perf.dart | 11 +++ .../animated_placeholder_perf_test.dart | 16 +++++ .../bin/tasks/animated_placeholder_perf.dart | 12 ++++ dev/devicelab/lib/tasks/perf_tests.dart | 9 +++ dev/devicelab/manifest.yaml | 9 +++ 8 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 dev/benchmarks/macrobenchmarks/lib/src/animated_placeholder.dart create mode 100644 dev/benchmarks/macrobenchmarks/test_driver/animated_placeholder_perf.dart create mode 100644 dev/benchmarks/macrobenchmarks/test_driver/animated_placeholder_perf_test.dart create mode 100644 dev/devicelab/bin/tasks/animated_placeholder_perf.dart diff --git a/dev/benchmarks/macrobenchmarks/lib/common.dart b/dev/benchmarks/macrobenchmarks/lib/common.dart index 3742c1608d..3cd0f4a6d6 100644 --- a/dev/benchmarks/macrobenchmarks/lib/common.dart +++ b/dev/benchmarks/macrobenchmarks/lib/common.dart @@ -10,3 +10,4 @@ const String kSimpleAnimationRouteName = '/simple_animation'; const String kPictureCacheRouteName = '/picture_cache'; const String kLargeImagesRouteName = '/large_images'; const String kTextRouteName = '/text'; +const String kAnimatedPlaceholderRouteName = '/animated_placeholder'; diff --git a/dev/benchmarks/macrobenchmarks/lib/main.dart b/dev/benchmarks/macrobenchmarks/lib/main.dart index 67b87f9775..4576b7a2eb 100644 --- a/dev/benchmarks/macrobenchmarks/lib/main.dart +++ b/dev/benchmarks/macrobenchmarks/lib/main.dart @@ -7,6 +7,7 @@ import 'package:macrobenchmarks/src/large_images.dart'; import 'package:macrobenchmarks/src/picture_cache.dart'; import 'common.dart'; +import 'src/animated_placeholder.dart'; import 'src/backdrop_filter.dart'; import 'src/cubic_bezier.dart'; import 'src/cull_opacity.dart'; @@ -14,7 +15,7 @@ import 'src/post_backdrop_filter.dart'; import 'src/simple_animation.dart'; import 'src/text.dart'; -const String kMacrobenchmarks ='Macrobenchmarks'; +const String kMacrobenchmarks = 'Macrobenchmarks'; void main() => runApp(const MacrobenchmarksApp()); @@ -36,6 +37,7 @@ class MacrobenchmarksApp extends StatelessWidget { kPictureCacheRouteName: (BuildContext context) => PictureCachePage(), kLargeImagesRouteName: (BuildContext context) => LargeImagesPage(), kTextRouteName: (BuildContext context) => TextPage(), + kAnimatedPlaceholderRouteName: (BuildContext context) => AnimatedPlaceholderPage(), }, ); } @@ -106,6 +108,13 @@ class HomePage extends StatelessWidget { Navigator.pushNamed(context, kTextRouteName); }, ), + RaisedButton( + key: const Key(kAnimatedPlaceholderRouteName), + child: const Text('Animated Placeholder'), + onPressed: () { + Navigator.pushNamed(context, kAnimatedPlaceholderRouteName); + }, + ), ], ), ); diff --git a/dev/benchmarks/macrobenchmarks/lib/src/animated_placeholder.dart b/dev/benchmarks/macrobenchmarks/lib/src/animated_placeholder.dart new file mode 100644 index 0000000000..39b2dbce64 --- /dev/null +++ b/dev/benchmarks/macrobenchmarks/lib/src/animated_placeholder.dart @@ -0,0 +1,68 @@ +// 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:convert'; +import 'dart:ui' as ui show Codec; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +/// An animated GIF image with 3 1x1 pixel frames (a red, green, and blue +/// frames). The GIF animates forever, and each frame has a 100ms delay. +const String kAnimatedGif = 'R0lGODlhAQABAKEDAAAA//8AAAD/AP///yH/C05FVFNDQVBFMi' + '4wAwEAAAAh+QQACgD/ACwAAAAAAQABAAACAkwBACH5BAAKAP8A' + 'LAAAAAABAAEAAAICVAEAIfkEAAoA/wAsAAAAAAEAAQAAAgJEAQ' + 'A7'; + +/// A 50x50 blue square png +const String kBlueSquare = 'iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAASEl' + 'EQVR42u3PMQ0AMAgAsGFjL/4tYQU08JLWQSN/9TsgRERERERERE' + 'REREREREREREREREREREREREREREREREREREREREQ2BgNuaUcSj' + 'uqqAAAAAElFTkSuQmCC'; + +/// A 10x10 grid of animated looping placeholder gifts that fade into a +/// blue square. +class AnimatedPlaceholderPage extends StatelessWidget { + @override + Widget build(BuildContext context) { + return GridView.builder( + itemCount: 100, + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 10), + itemBuilder: (BuildContext context, int index) { + return FadeInImage( + placeholder: DelayedBase64Image(Duration.zero, kAnimatedGif), + image: DelayedBase64Image(Duration(milliseconds: 100 * index), kBlueSquare), + ); + }, + ); + } +} + +int _key = 0; +/// An image provider that is always unique from other DelayedBase64Images and +/// simulates a delay in loading. +class DelayedBase64Image extends ImageProvider { + const DelayedBase64Image(this.delay, this.data); + + final String data; + + final Duration delay; + + @override + Future obtainKey(ImageConfiguration configuration) { + return SynchronousFuture(_key++); + } + + @override + ImageStreamCompleter load(int key, DecoderCallback decode) { + return MultiFrameImageStreamCompleter( + codec: Future.delayed( + delay, + () => decode(base64.decode(data)), + ), + scale: 1.0, + ); + } +} diff --git a/dev/benchmarks/macrobenchmarks/test_driver/animated_placeholder_perf.dart b/dev/benchmarks/macrobenchmarks/test_driver/animated_placeholder_perf.dart new file mode 100644 index 0000000000..8169d132b6 --- /dev/null +++ b/dev/benchmarks/macrobenchmarks/test_driver/animated_placeholder_perf.dart @@ -0,0 +1,11 @@ +// 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_driver/driver_extension.dart'; +import 'package:macrobenchmarks/main.dart' as app; + +void main() { + enableFlutterDriverExtension(); + app.main(); +} diff --git a/dev/benchmarks/macrobenchmarks/test_driver/animated_placeholder_perf_test.dart b/dev/benchmarks/macrobenchmarks/test_driver/animated_placeholder_perf_test.dart new file mode 100644 index 0000000000..7e6ca0cc8a --- /dev/null +++ b/dev/benchmarks/macrobenchmarks/test_driver/animated_placeholder_perf_test.dart @@ -0,0 +1,16 @@ +// 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:macrobenchmarks/common.dart'; + +import 'util.dart'; + +void main() { + macroPerfTest( + 'animated_placeholder_perf', + kAnimatedPlaceholderRouteName, + pageDelay: const Duration(seconds: 1), + duration: const Duration(seconds: 15), + ); +} diff --git a/dev/devicelab/bin/tasks/animated_placeholder_perf.dart b/dev/devicelab/bin/tasks/animated_placeholder_perf.dart new file mode 100644 index 0000000000..d5d52acbeb --- /dev/null +++ b/dev/devicelab/bin/tasks/animated_placeholder_perf.dart @@ -0,0 +1,12 @@ +// 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_devicelab/framework/adb.dart'; +import 'package:flutter_devicelab/framework/framework.dart'; +import 'package:flutter_devicelab/tasks/perf_tests.dart'; + +Future main() async { + deviceOperatingSystem = DeviceOperatingSystem.android; + await task(createAnimatedPlaceholderPerfTest()); +} diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index 529eadc47d..d2a1485e5b 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -81,6 +81,15 @@ TaskFunction createSimpleAnimationPerfTest({bool needsMeasureCpuGpu = false}) { ).run; } +TaskFunction createAnimatedPlaceholderPerfTest({bool needsMeasureCpuGpu = false}) { + return PerfTest( + '${flutterDirectory.path}/dev/benchmarks/macrobenchmarks', + 'test_driver/animated_placeholder_perf.dart', + 'animated_placeholder_perf', + needsMeasureCpuGPu: needsMeasureCpuGpu, + ).run; +} + TaskFunction createPictureCachePerfTest() { return PerfTest( '${flutterDirectory.path}/dev/benchmarks/macrobenchmarks', diff --git a/dev/devicelab/manifest.yaml b/dev/devicelab/manifest.yaml index 81a78c364e..910bdee668 100644 --- a/dev/devicelab/manifest.yaml +++ b/dev/devicelab/manifest.yaml @@ -700,6 +700,15 @@ tasks: stage: devicelab required_agent_capabilities: ["mac/android"] + animated_placeholder_perf: + description: > + Measures frame build and rasterizer times, as well as frame build counts + for a grid of images that uses FadeInImage with an animated gif as the + placeholder. + stage: devicelab + required_agent_capabilities: ["linux/android"] + flaky: true + analyzer_benchmark: description: > Measures the speed of Dart analyzer.