Unverified Commit d25a5c37 authored by Abhishek Ghaskata's avatar Abhishek Ghaskata Committed by GitHub

Migrate microbrenchmarks to null safety (#83619)

parent 15317b9e
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
import 'dart:convert' show json; import 'dart:convert' show json;
import 'package:meta/meta.dart';
/// This class knows how to format benchmark results for machine and human /// This class knows how to format benchmark results for machine and human
/// consumption. /// consumption.
/// ///
...@@ -31,7 +29,7 @@ class BenchmarkResultPrinter { ...@@ -31,7 +29,7 @@ class BenchmarkResultPrinter {
/// result value. [unit] is the unit of measurement, such as "ms", "km", "h". /// 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 /// [name] is a computer-readable name of the result used as a key in the JSON
/// serialization of the results. /// 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)); _results.add(_BenchmarkResult(description, value, unit, name));
} }
......
...@@ -44,24 +44,24 @@ Future<void> main() async { ...@@ -44,24 +44,24 @@ Future<void> main() async {
// Wait for frame rendering to stabilize. // Wait for frame rendering to stabilize.
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
await SchedulerBinding.instance.endOfFrame; await SchedulerBinding.instance?.endOfFrame;
} }
final Stopwatch watch = Stopwatch(); 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 // 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) { while (elementCount < 2458) {
await Future<void>.delayed(Duration.zero); 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'); print('element count: $elementCount');
watch.start(); watch.start();
for (int i = 0; i < _kNumIters; i += 1) { for (int i = 0; i < _kNumIters; i += 1) {
final List<Element> allElements = collectAllElementsFrom( final List<Element> allElements = collectAllElementsFrom(
WidgetsBinding.instance.renderViewElement, WidgetsBinding.instance!.renderViewElement!,
skipOffstage: false, skipOffstage: false,
).toList(); ).toList();
allElements.clear(); allElements.clear();
......
...@@ -9,7 +9,7 @@ import '../common.dart'; ...@@ -9,7 +9,7 @@ import '../common.dart';
const int _kNumIters = 10000; 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(); final Stopwatch watch = Stopwatch();
print('$description benchmark...'); print('$description benchmark...');
watch.start(); watch.start();
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ButtonMatrixApp extends StatefulWidget { class ButtonMatrixApp extends StatefulWidget {
const ButtonMatrixApp({Key key}) : super(key: key); const ButtonMatrixApp({Key? key}) : super(key: key);
@override @override
ButtonMatrixAppState createState() => ButtonMatrixAppState(); ButtonMatrixAppState createState() => ButtonMatrixAppState();
......
...@@ -10,7 +10,7 @@ import 'data/velocity_tracker_data.dart'; ...@@ -10,7 +10,7 @@ import 'data/velocity_tracker_data.dart';
const int _kNumIters = 10000; const int _kNumIters = 10000;
class TrackerBenchmark { class TrackerBenchmark {
TrackerBenchmark({ this.name, this.tracker }); TrackerBenchmark({required this.name, required this.tracker });
final VelocityTracker tracker; final VelocityTracker tracker;
final String name; final String name;
......
...@@ -80,7 +80,7 @@ String consumeSpan(Iterable<InlineSpanSemanticsInformation> items) { ...@@ -80,7 +80,7 @@ String consumeSpan(Iterable<InlineSpanSemanticsInformation> items) {
Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<InlineSpanSemanticsInformation> inputs) sync* { Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<InlineSpanSemanticsInformation> inputs) sync* {
String workingText = ''; String workingText = '';
String workingLabel; String? workingLabel;
for (final InlineSpanSemanticsInformation info in inputs) { for (final InlineSpanSemanticsInformation info in inputs) {
if (info.requiresOwnNode) { if (info.requiresOwnNode) {
if (workingText != null) { if (workingText != null) {
...@@ -92,8 +92,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin ...@@ -92,8 +92,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
} else { } else {
workingText += info.text; workingText += info.text;
workingLabel ??= ''; workingLabel ??= '';
if (info.semanticsLabel != null) { final String? infoSemanticsLabel = info.semanticsLabel;
workingLabel += info.semanticsLabel; if (infoSemanticsLabel != null) {
workingLabel += infoSemanticsLabel;
} else { } else {
workingLabel += info.text; workingLabel += info.text;
} }
...@@ -108,7 +109,7 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin ...@@ -108,7 +109,7 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(List<Inlin
Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpanSemanticsInformation> inputs) { Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpanSemanticsInformation> inputs) {
String workingText = ''; String workingText = '';
String workingLabel; String? workingLabel;
final List<InlineSpanSemanticsInformation> result = <InlineSpanSemanticsInformation>[]; final List<InlineSpanSemanticsInformation> result = <InlineSpanSemanticsInformation>[];
for (final InlineSpanSemanticsInformation info in inputs) { for (final InlineSpanSemanticsInformation info in inputs) {
if (info.requiresOwnNode) { if (info.requiresOwnNode) {
...@@ -121,8 +122,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpa ...@@ -121,8 +122,9 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(List<InlineSpa
} else { } else {
workingText += info.text; workingText += info.text;
workingLabel ??= ''; workingLabel ??= '';
if (info.semanticsLabel != null) { final String? infoSemanticsLabel = info.semanticsLabel;
workingLabel += info.semanticsLabel; if (infoSemanticsLabel != null) {
workingLabel += infoSemanticsLabel;
} else { } else {
workingLabel += info.text; workingLabel += info.text;
} }
......
...@@ -17,7 +17,7 @@ class BenchmarkingBinding extends LiveTestWidgetsFlutterBinding { ...@@ -17,7 +17,7 @@ class BenchmarkingBinding extends LiveTestWidgetsFlutterBinding {
final Stopwatch stopwatch; final Stopwatch stopwatch;
@override @override
void handleBeginFrame(Duration rawTimeStamp) { void handleBeginFrame(Duration? rawTimeStamp) {
stopwatch.start(); stopwatch.start();
super.handleBeginFrame(rawTimeStamp); super.handleBeginFrame(rawTimeStamp);
} }
...@@ -68,7 +68,7 @@ Future<void> main() async { ...@@ -68,7 +68,7 @@ Future<void> main() async {
// Time how long each frame takes // Time how long each frame takes
cpuWatch.reset(); cpuWatch.reset();
while (SchedulerBinding.instance.hasScheduledFrame) { while (SchedulerBinding.instance!.hasScheduledFrame) {
await tester.pump(); await tester.pump();
totalSubsequentFramesIterationCount += 1; totalSubsequentFramesIterationCount += 1;
} }
......
...@@ -33,18 +33,18 @@ Future<void> main() async { ...@@ -33,18 +33,18 @@ Future<void> main() async {
final TestViewConfiguration big = TestViewConfiguration( final TestViewConfiguration big = TestViewConfiguration(
size: const Size(360.0, 640.0), size: const Size(360.0, 640.0),
window: RendererBinding.instance.window, window: RendererBinding.instance?.window,
); );
final TestViewConfiguration small = TestViewConfiguration( final TestViewConfiguration small = TestViewConfiguration(
size: const Size(355.0, 635.0), 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; binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmark;
watch.start(); watch.start();
while (watch.elapsed < kBenchmarkTime) { while (watch.elapsed < kBenchmarkTime) {
renderView.configuration = iterations.isEven ? big : small; renderView?.configuration = iterations.isEven ? big : small;
await tester.pumpBenchmark(Duration(milliseconds: iterations * 16)); await tester.pumpBenchmark(Duration(milliseconds: iterations * 16));
iterations += 1; iterations += 1;
} }
......
...@@ -2,7 +2,7 @@ name: microbenchmarks ...@@ -2,7 +2,7 @@ name: microbenchmarks
description: Small benchmarks for very specific parts of the Flutter framework. description: Small benchmarks for very specific parts of the Flutter framework.
environment: environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"
dependencies: dependencies:
meta: 1.4.0 meta: 1.4.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment