-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[devicelab] add benchmark for complex non-intersecting widgets with p…
…latform views (#116436)
- Loading branch information
1 parent
4643f83
commit 08a2635
Showing
8 changed files
with
237 additions
and
4 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
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
115 changes: 115 additions & 0 deletions
115
dev/benchmarks/platform_views_layout/lib/main_non_intersecting.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,115 @@ | ||
// 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:flutter/scheduler.dart' show timeDilation; | ||
|
||
void main() { | ||
runApp( | ||
const PlatformViewApp() | ||
); | ||
} | ||
|
||
class PlatformViewApp extends StatefulWidget { | ||
const PlatformViewApp({ | ||
super.key, | ||
}); | ||
|
||
@override | ||
PlatformViewAppState createState() => PlatformViewAppState(); | ||
} | ||
|
||
class PlatformViewAppState extends State<PlatformViewApp> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
theme: ThemeData.light(), | ||
title: 'Advanced Layout', | ||
home: const PlatformViewLayout(), | ||
); | ||
} | ||
|
||
void toggleAnimationSpeed() { | ||
setState(() { | ||
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0; | ||
}); | ||
} | ||
} | ||
|
||
class PlatformViewLayout extends StatelessWidget { | ||
const PlatformViewLayout({ super.key }); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: const Text('Platform View Scrolling Layout')), | ||
body: ListView.builder( | ||
key: const Key('platform-views-scroll'), // This key is used by the driver test. | ||
itemCount: 200, | ||
itemBuilder: (BuildContext context, int index) { | ||
return Padding( | ||
padding: const EdgeInsets.all(5.0), | ||
child: Material( | ||
elevation: (index % 5 + 1).toDouble(), | ||
color: Colors.white, | ||
child: index.isEven | ||
? CustomPaint(painter: ExpensivePainter(), size: const Size(400, 200)) | ||
: const DummyPlatformView() | ||
), | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class DummyPlatformView extends StatelessWidget { | ||
const DummyPlatformView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
const String viewType = 'benchmarks/platform_views_layout/DummyPlatformView'; | ||
late Widget nativeView; | ||
if (Platform.isIOS) { | ||
nativeView = const UiKitView( | ||
viewType: viewType, | ||
); | ||
} else if (Platform.isAndroid) { | ||
nativeView = const AndroidView( | ||
viewType: viewType, | ||
); | ||
} else { | ||
assert(false, 'Invalid platform'); | ||
} | ||
return Container( | ||
color: Colors.purple, | ||
height: 200.0, | ||
child: nativeView, | ||
); | ||
} | ||
} | ||
|
||
class ExpensivePainter extends CustomPainter { | ||
@override | ||
void paint(Canvas canvas, Size size) { | ||
final double boxWidth = size.width / 50; | ||
final double boxHeight = size.height / 50; | ||
for (int i = 0; i < 50; i++) { | ||
for (int j = 0; j < 50; j++) { | ||
final Rect rect = Rect.fromLTWH(i * boxWidth, j * boxHeight, boxWidth, boxHeight); | ||
canvas.drawRect(rect, Paint() | ||
..style = PaintingStyle.fill | ||
..color = Colors.red | ||
); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
bool shouldRepaint(covariant CustomPainter oldDelegate) { | ||
return false; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
dev/benchmarks/platform_views_layout/test_driver/scroll_perf_non_intersecting_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,62 @@ | ||
// 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)); | ||
|
||
await driver.forceGC(); | ||
|
||
final Timeline timeline = await driver.traceAction(() async { | ||
// Find the scrollable stock list | ||
final SerializableFinder list = find.byValueKey(listKey); | ||
expect(list, isNotNull); | ||
|
||
for (int j = 0; j < 5; j ++) { | ||
// 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_non_intersecting'); | ||
}); | ||
}, timeout: Timeout.none); | ||
}); | ||
} |
13 changes: 13 additions & 0 deletions
13
...benchmarks/platform_views_layout/test_driver/uikit_view_scroll_perf_non_intersecting.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_non_intersecting.dart' as app; | ||
|
||
void main() { | ||
enableFlutterDriverExtension(); | ||
runApp(const app.PlatformViewApp()); | ||
} |
12 changes: 12 additions & 0 deletions
12
...bin/tasks/platform_views_scroll_perf_non_intersecting_impeller_ios__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(createUiKitViewScrollPerfNonIntersectingTest(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