Update VelocityTracker (4) (#139166)
This updates the implementation to use the stopwatch from the Clock object and pipes it through to the TestWidgetsFlutterBinding so it will be kept in sync with FakeAsync. Relands https://github.com/flutter/flutter/pull/138843 attempted to reland https://github.com/flutter/flutter/pull/137381 which attempted to reland #132291 Fixes https://github.com/flutter/flutter/issues/97761 1. The original change was reverted due to flakiness it introduced in tests that use fling gestures. * Using a mocked clock through the test binding fixes this now 2. It was reverted a second time because a change at tip of tree broke it, exposing memory leaks, but it was not rebased before landing. * These leaks are now fixed 3. It was reverted a third time, because we were so excellently quick to revert those other times, that we did not notice the broken benchmark that only runs in postsubmit. * The benchmark is now fixed
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../common.dart';
|
||||
import 'data/velocity_tracker_data.dart';
|
||||
@@ -16,38 +17,43 @@ class TrackerBenchmark {
|
||||
final String name;
|
||||
}
|
||||
|
||||
void main() {
|
||||
Future<void> main() async {
|
||||
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
|
||||
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
||||
final List<TrackerBenchmark> benchmarks = <TrackerBenchmark>[
|
||||
TrackerBenchmark(name: 'velocity_tracker_iteration', tracker: VelocityTracker.withKind(PointerDeviceKind.touch)),
|
||||
TrackerBenchmark(name: 'velocity_tracker_iteration_ios_fling', tracker: IOSScrollViewFlingVelocityTracker(PointerDeviceKind.touch)),
|
||||
TrackerBenchmark(name: 'velocity_tracker_iteration',
|
||||
tracker: VelocityTracker.withKind(PointerDeviceKind.touch)),
|
||||
TrackerBenchmark(name: 'velocity_tracker_iteration_ios_fling',
|
||||
tracker: IOSScrollViewFlingVelocityTracker(PointerDeviceKind.touch)),
|
||||
];
|
||||
final Stopwatch watch = Stopwatch();
|
||||
|
||||
for (final TrackerBenchmark benchmark in benchmarks) {
|
||||
print('${benchmark.name} benchmark...');
|
||||
final VelocityTracker tracker = benchmark.tracker;
|
||||
watch.reset();
|
||||
watch.start();
|
||||
for (int i = 0; i < _kNumIters; i += 1) {
|
||||
for (final PointerEvent event in velocityEventData) {
|
||||
if (event is PointerDownEvent || event is PointerMoveEvent) {
|
||||
tracker.addPosition(event.timeStamp, event.position);
|
||||
}
|
||||
if (event is PointerUpEvent) {
|
||||
tracker.getVelocity();
|
||||
await benchmarkWidgets((WidgetTester tester) async {
|
||||
for (final TrackerBenchmark benchmark in benchmarks) {
|
||||
print('${benchmark.name} benchmark...');
|
||||
final VelocityTracker tracker = benchmark.tracker;
|
||||
watch.reset();
|
||||
watch.start();
|
||||
for (int i = 0; i < _kNumIters; i += 1) {
|
||||
for (final PointerEvent event in velocityEventData) {
|
||||
if (event is PointerDownEvent || event is PointerMoveEvent) {
|
||||
tracker.addPosition(event.timeStamp, event.position);
|
||||
}
|
||||
if (event is PointerUpEvent) {
|
||||
tracker.getVelocity();
|
||||
}
|
||||
}
|
||||
}
|
||||
watch.stop();
|
||||
|
||||
printer.addResult(
|
||||
description: 'Velocity tracker: ${tracker.runtimeType}',
|
||||
value: watch.elapsedMicroseconds / _kNumIters,
|
||||
unit: 'µs per iteration',
|
||||
name: benchmark.name,
|
||||
);
|
||||
}
|
||||
watch.stop();
|
||||
printer.addResult(
|
||||
description: 'Velocity tracker: ${tracker.runtimeType}',
|
||||
value: watch.elapsedMicroseconds / _kNumIters,
|
||||
unit: 'µs per iteration',
|
||||
name: benchmark.name,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
printer.printToStdout();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user