-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ios]A typical news app benchmark with bottom ad banner (#150991)
This is a very common usage of ad so we want to make sure it's performant. From the video, it scrolls quite smoothly, but we want to see the numbers, and keep monitoring it in case of regression. https://github.com/flutter/flutter/assets/41930132/c7811c15-ac07-4989-a8a9-3c128e08cbe0 *List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.* Fixes #150230 *If you had to change anything in the [flutter/tests] repo, include a link to the migration guide as per the [breaking change policy].*
- Loading branch information
1 parent
c082abe
commit 86ac077
Showing
7 changed files
with
189 additions
and
0 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
83 changes: 83 additions & 0 deletions
83
dev/benchmarks/platform_views_layout/lib/main_bottom_ad_banner.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,83 @@ | ||
// 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:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:google_mobile_ads/google_mobile_ads.dart'; | ||
|
||
void main() { | ||
runApp( | ||
const PlatformViewApp() | ||
); | ||
} | ||
|
||
class PlatformViewApp extends StatefulWidget { | ||
const PlatformViewApp({ | ||
super.key, | ||
}); | ||
|
||
@override | ||
PlatformViewAppState createState() => PlatformViewAppState(); | ||
} | ||
|
||
class PlatformViewAppState extends State<PlatformViewApp> { | ||
|
||
Widget _getBannerWidget() { | ||
// Test IDs from Admob: | ||
// https://developers.google.com/admob/ios/test-ads | ||
// https://developers.google.com/admob/android/test-ads | ||
final String bannerId = Platform.isAndroid | ||
? 'ca-app-pub-3940256099942544/6300978111' | ||
: 'ca-app-pub-3940256099942544/2934735716'; | ||
final BannerAd bannerAd = BannerAd( | ||
adUnitId: bannerId, | ||
request: const AdRequest(), | ||
size: AdSize.banner, | ||
listener: const BannerAdListener(), | ||
); | ||
bannerAd.load(); | ||
return Align( | ||
alignment: Alignment.bottomCenter, | ||
// Use 320x50 Admob standard banner size. | ||
child: SizedBox( | ||
width: 320, | ||
height: 50, | ||
child: AdWidget(ad: bannerAd), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
theme: ThemeData.light(), | ||
title: 'Advanced Layout', | ||
home: Scaffold( | ||
appBar: AppBar(title: const Text('Platform View Bottom Ad Banner')), | ||
body: Column( | ||
children: <Widget>[ | ||
Expanded( | ||
child: ListView.builder( | ||
key: const Key('platform-views-scroll'), // This key is used by the driver test. | ||
itemCount: 250, | ||
itemBuilder: (BuildContext context, int index) { | ||
return const Card( | ||
elevation: 2, | ||
child: ListTile( | ||
title: Text('Breaking News!'), | ||
subtitle: Text('Huge breaking news! Here is huge and breaking news which is both huge and breaking.'), | ||
leading: FlutterLogo(), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
_getBannerWidget(), | ||
] | ||
) | ||
), | ||
); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
dev/benchmarks/platform_views_layout/test_driver/scroll_perf_bottom_ad_banner_test.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,59 @@ | ||
// 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/flutter_driver.dart'; | ||
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf; | ||
|
||
void main() { | ||
group('scrolling performance test', () { | ||
late FlutterDriver driver; | ||
|
||
setUpAll(() async { | ||
driver = await FlutterDriver.connect(); | ||
|
||
await driver.waitUntilFirstFrameRasterized(); | ||
}); | ||
|
||
tearDownAll(() async { | ||
driver.close(); | ||
}); | ||
|
||
Future<void> testScrollPerf(String listKey, String summaryName) async { | ||
// The slight initial delay avoids starting the timing during a | ||
// period of increased load on the device. Without this delay, the | ||
// benchmark has greater noise. | ||
// See: https://github.com/flutter/flutter/issues/19434 | ||
await Future<void>.delayed(const Duration(milliseconds: 250)); | ||
|
||
final Timeline timeline = await driver.traceAction(() async { | ||
// Find the scrollable stock list | ||
final SerializableFinder list = find.byValueKey(listKey); | ||
|
||
for (int j = 0; j < 5; j = 1) { | ||
// Scroll down | ||
for (int i = 0; i < 5; i = 1) { | ||
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300)); | ||
await Future<void>.delayed(const Duration(milliseconds: 500)); | ||
} | ||
|
||
// Scroll up | ||
for (int i = 0; i < 5; i = 1) { | ||
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300)); | ||
await Future<void>.delayed(const Duration(milliseconds: 500)); | ||
} | ||
} | ||
}); | ||
|
||
final TimelineSummary summary = TimelineSummary.summarize(timeline); | ||
await summary.writeTimelineToFile(summaryName, pretty: true); | ||
} | ||
|
||
test('platform_views_scroll_perf', () async { | ||
// Disable frame sync, since there are ongoing animations. | ||
await driver.runUnsynchronized(() async { | ||
await testScrollPerf('platform-views-scroll', 'platform_views_scroll_perf_bottom_ad_banner'); | ||
}); | ||
}, timeout: Timeout.none); | ||
}); | ||
} |
13 changes: 13 additions & 0 deletions
13
...benchmarks/platform_views_layout/test_driver/uikit_view_scroll_perf_bottom_ad_banner.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,13 @@ | ||
// 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/widgets.dart'; | ||
import 'package:flutter_driver/driver_extension.dart'; | ||
|
||
import 'package:platform_views_layout/main_bottom_ad_banner.dart' as app; | ||
|
||
void main() { | ||
enableFlutterDriverExtension(); | ||
runApp(const app.PlatformViewApp()); | ||
} |
12 changes: 12 additions & 0 deletions
12
dev/devicelab/bin/tasks/platform_views_scroll_perf_bottom_ad_banner__timeline_summary.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,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/devices.dart'; | ||
import 'package:flutter_devicelab/framework/framework.dart'; | ||
import 'package:flutter_devicelab/tasks/perf_tests.dart'; | ||
|
||
Future<void> main() async { | ||
deviceOperatingSystem = DeviceOperatingSystem.ios; | ||
await task(createUiKitViewScrollPerfBottomAdBannerTest(enableImpeller: true)); | ||
} |
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