Skip to content

Instantly share code, notes, and snippets.

How to write a render speed test for Flutter

There are many ways to write a render speed test for Flutter. In this article, we give one example that uses the [Flutter driver][flutter_driver], the [dev/benchmarks/macrobenchmarks][macrobenchmarks] app, and the [dev/devicelab][devicelab] to automatically collect metrics for every future Flutter commit and send them to [flutter/cocoon][cocoon].

The instructions below are for contributors who want to expose a Flutter SDK (framework or engine) performance issue, or write pull requests to fix such issues. If one only needs to test the performance of a particular Flutter app, please reference

Since Flutter Web and Flutter Desktop are still in their early stages, the content here is only well tested and supported on mobile platforms (Android/iOS). We'll come up with docs on how to write performance tests for W

@liyuqian
liyuqian / main.dart
Created June 6, 2020 18:49
TightClipper to avoid some AA artifacts
import 'package:flutter/material.dart';
void main() {
runApp(IssueDemoApp());
}
class IssueDemoApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
https://dart-review.googlesource.com/c/sdk/+/127920
https://dart-review.googlesource.com/c/sdk/+/128200
https://dart-review.googlesource.com/c/sdk/+/127921
https://github.com/flutter/engine/pull/14323
https://github.com/flutter/engine/pull/14521
https://github.com/flutter/engine/pull/14319
https://github.com/flutter/flutter/pull/47742
@liyuqian
liyuqian / main.dart
Created January 29, 2020 14:49
Sample app of CustomPaint not setting isComplex
import 'package:flutter/material.dart';
final imageUrl =
'https://cdn.vox-cdn.com/thumbor/yacVJaRnOvWiuIO3L6pe5Tmlv68=/0x26:640x453/920x613/filters:focal(0x26:640x453):format(webp)/cdn.vox-cdn.com/assets/1275052/kitten_field_jump.jpeg';
class CostlyToRasterize extends StatelessWidget {
@override
Widget build(BuildContext context) {
const color = Color(0xff00ff);
return Stack(
diff --git a/lib/ui/window/pointer_data_packet.cc b/lib/ui/window/pointer_data_packet.cc
index bd2abd6f1..61f68c561 100644
--- a/lib/ui/window/pointer_data_packet.cc
+++ b/lib/ui/window/pointer_data_packet.cc
@@ -20,8 +20,9 @@ void PointerDataPacket::SetPointerData(size_t i, const PointerData& data) {
memcpy(&data_[i * sizeof(PointerData)], &data, sizeof(PointerData));
}
-void PointerDataPacket::GetPointerData(size_t i, PointerData* data) const {
- memcpy(data, &data_[i * sizeof(PointerData)], sizeof(PointerData));
@liyuqian
liyuqian / i41469.dart
Last active December 5, 2019 01:15
i41469.dart
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
import random
def sample():
phase = random.random()
if phase < 3/8.0:
return random.random(), random.random()
elif phase < 6/8.0:
return random.random() + 1, random.random() + 1
elif phase < 7/8.0:
return random.random() + 1, random.random()
import 'dart:math';
import 'dart:io';
import 'package:console/console.dart';
void main() {
Console.init();
double a = _askInputAndClearConsole('A, please tell me your value: ');
double b = _askInputAndClearConsole('B, please tell me your cost: ');
if (a < b) {
@liyuqian
liyuqian / main.dart
Created August 1, 2019 20:40
Cache BackdropFilter with Snapshot
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@liyuqian
liyuqian / expensive.dart
Last active July 3, 2019 21:41
Example Flutter app that has janky animations caused by custom Dart code outside of Flutter framework.
/// Run this with `flutter run --profile` and check its tracing in the observatory.
///
/// You should see janky animations of the CircularProgressIndicator caused by
/// expensiveFunction which has nothing to do with the Flutter framework.
import 'package:flutter/material.dart';
import 'dart:developer';
void expensiveFunction() {
// It will be very hard to tell why it's so janky without the following Timeline tracing
// (if the expensiveFunction has a much more innocent name, and is burried beneath hundreds