Migrate microbrenchmarks to null safety (#83619)
This commit is contained in:
parent
15317b9e8d
commit
d25a5c376d
@ -4,8 +4,6 @@
|
||||
|
||||
import 'dart:convert' show json;
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
/// This class knows how to format benchmark results for machine and human
|
||||
/// consumption.
|
||||
///
|
||||
@ -31,7 +29,7 @@ class BenchmarkResultPrinter {
|
||||
/// result value. [unit] is the unit of measurement, such as "ms", "km", "h".
|
||||
/// [name] is a computer-readable name of the result used as a key in the JSON
|
||||
/// serialization of the results.
|
||||
void addResult({ @required String description, @required double value, @required String unit, @required String name }) {
|
||||
void addResult({ required String description, required double value, required String unit, required String name }) {
|
||||
_results.add(_BenchmarkResult(description, value, unit, name));
|
||||
}
|
||||
|
||||
|
@ -44,24 +44,24 @@ Future<void> main() async {
|
||||
|
||||
// Wait for frame rendering to stabilize.
|
||||
for (int i = 0; i < 5; i++) {
|
||||
await SchedulerBinding.instance.endOfFrame;
|
||||
await SchedulerBinding.instance?.endOfFrame;
|
||||
}
|
||||
|
||||
final Stopwatch watch = Stopwatch();
|
||||
|
||||
print('flutter_test allElements benchmark... (${WidgetsBinding.instance.renderViewElement})');
|
||||
print('flutter_test allElements benchmark... (${WidgetsBinding.instance?.renderViewElement})');
|
||||
// Make sure we get enough elements to process for consistent benchmark runs
|
||||
int elementCount = collectAllElementsFrom(WidgetsBinding.instance.renderViewElement, skipOffstage: false).length;
|
||||
int elementCount = collectAllElementsFrom(WidgetsBinding.instance!.renderViewElement!, skipOffstage: false).length;
|
||||
while (elementCount < 2458) {
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
elementCount = collectAllElementsFrom(WidgetsBinding.instance.renderViewElement, skipOffstage: false).length;
|
||||
elementCount = collectAllElementsFrom(WidgetsBinding.instance!.renderViewElement!, skipOffstage: false).length;
|
||||
}
|
||||
print('element count: $elementCount');
|
||||
|
||||
watch.start();
|
||||
for (int i = 0; i < _kNumIters; i += 1) {
|
||||
final List<Element> allElements = collectAllElementsFrom(
|
||||
WidgetsBinding.instance.renderViewElement,
|
||||
WidgetsBinding.instance!.renderViewElement!,
|
||||
skipOffstage: false,
|
||||
).toList();
|
||||
allElements.clear();
|
||||
|
@ -9,7 +9,7 @@ import '../common.dart';
|
||||
|
||||
const int _kNumIters = 10000;
|
||||
|
||||
void _testCurve(Curve curve, {String name, String description, BenchmarkResultPrinter printer}) {
|
||||
void _testCurve(Curve curve, {required String name, required String description, required BenchmarkResultPrinter printer}) {
|
||||
final Stopwatch watch = Stopwatch();
|
||||
print('$description benchmark...');
|
||||
watch.start();
|
||||
|
@ -5,7 +5,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ButtonMatrixApp extends StatefulWidget {
|
||||
const ButtonMatrixApp({Key key}) : super(key: key);
|
||||
const ButtonMatrixApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
ButtonMatrixAppState createState() => ButtonMatrixAppState();
|
||||
|
@ -10,7 +10,7 @@ import 'data/velocity_tracker_data.dart';
|
||||
const int _kNumIters = 10000;
|
||||
|
||||
class TrackerBenchmark {
|
||||
TrackerBenchmark({ this.name, this.tracker });
|
||||
TrackerBenchmark({required this.name, required this.tracker });
|
||||
|
||||
final VelocityTracker tracker;
|
||||
final String name;
|
||||
|
@ -80,7 +80,7 @@ String consumeSpan(Iterable<InlineSpanSemanticsInformation> items) {
|
||||
|
||||
Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<InlineSpanSemanticsInformation> inputs) sync* {
|
||||
String workingText = '';
|
||||
String workingLabel;
|
||||
String? workingLabel;
|
||||
for (final InlineSpanSemanticsInformation info in inputs) {
|
||||
if (info.requiresOwnNode) {
|
||||
if (workingText != null) {
|
||||
@ -92,8 +92,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
|
||||
} else {
|
||||
workingText += info.text;
|
||||
workingLabel ??= '';
|
||||
if (info.semanticsLabel != null) {
|
||||
workingLabel += info.semanticsLabel;
|
||||
final String? infoSemanticsLabel = info.semanticsLabel;
|
||||
if (infoSemanticsLabel != null) {
|
||||
workingLabel += infoSemanticsLabel;
|
||||
} else {
|
||||
workingLabel += info.text;
|
||||
}
|
||||
@ -108,7 +109,7 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
|
||||
|
||||
Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpanSemanticsInformation> inputs) {
|
||||
String workingText = '';
|
||||
String workingLabel;
|
||||
String? workingLabel;
|
||||
final List<InlineSpanSemanticsInformation> result = <InlineSpanSemanticsInformation>[];
|
||||
for (final InlineSpanSemanticsInformation info in inputs) {
|
||||
if (info.requiresOwnNode) {
|
||||
@ -121,8 +122,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpa
|
||||
} else {
|
||||
workingText += info.text;
|
||||
workingLabel ??= '';
|
||||
if (info.semanticsLabel != null) {
|
||||
workingLabel += info.semanticsLabel;
|
||||
final String? infoSemanticsLabel = info.semanticsLabel;
|
||||
if (infoSemanticsLabel != null) {
|
||||
workingLabel += infoSemanticsLabel;
|
||||
} else {
|
||||
workingLabel += info.text;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class BenchmarkingBinding extends LiveTestWidgetsFlutterBinding {
|
||||
final Stopwatch stopwatch;
|
||||
|
||||
@override
|
||||
void handleBeginFrame(Duration rawTimeStamp) {
|
||||
void handleBeginFrame(Duration? rawTimeStamp) {
|
||||
stopwatch.start();
|
||||
super.handleBeginFrame(rawTimeStamp);
|
||||
}
|
||||
@ -68,7 +68,7 @@ Future<void> main() async {
|
||||
|
||||
// Time how long each frame takes
|
||||
cpuWatch.reset();
|
||||
while (SchedulerBinding.instance.hasScheduledFrame) {
|
||||
while (SchedulerBinding.instance!.hasScheduledFrame) {
|
||||
await tester.pump();
|
||||
totalSubsequentFramesIterationCount += 1;
|
||||
}
|
||||
|
@ -33,18 +33,18 @@ Future<void> main() async {
|
||||
|
||||
final TestViewConfiguration big = TestViewConfiguration(
|
||||
size: const Size(360.0, 640.0),
|
||||
window: RendererBinding.instance.window,
|
||||
window: RendererBinding.instance?.window,
|
||||
);
|
||||
final TestViewConfiguration small = TestViewConfiguration(
|
||||
size: const Size(355.0, 635.0),
|
||||
window: RendererBinding.instance.window,
|
||||
window: RendererBinding.instance?.window,
|
||||
);
|
||||
final RenderView renderView = WidgetsBinding.instance.renderView;
|
||||
final RenderView? renderView = WidgetsBinding.instance?.renderView;
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmark;
|
||||
|
||||
watch.start();
|
||||
while (watch.elapsed < kBenchmarkTime) {
|
||||
renderView.configuration = iterations.isEven ? big : small;
|
||||
renderView?.configuration = iterations.isEven ? big : small;
|
||||
await tester.pumpBenchmark(Duration(milliseconds: iterations * 16));
|
||||
iterations += 1;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ name: microbenchmarks
|
||||
description: Small benchmarks for very specific parts of the Flutter framework.
|
||||
|
||||
environment:
|
||||
sdk: ">=2.0.0-dev.68.0 <3.0.0"
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
meta: 1.4.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user