-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IOS]Image.toByteData()
is super slow on Flutter 3
#106773
Comments
#104300 same issues, because it was closed,so I had to create a new one. |
Hi @ssyzh, Thanks for filing the issue. I am able to reproduce the issue. Compared to stable 2.10.5 I am seeing 3x delay on the latest stable and the master channel on IOS. While the results are nearly the same on Android code sampleimport 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final GlobalKey sharePageKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: RepaintBoundary(
key: sharePageKey,
child: Column(
children: [
Text(List.generate(200, (index) => "Text").join("#")),
Image.network(
"http://pic1.win4000.com/wallpaper/2020-10-10/5f811214aa09e.jpg",
width: double.infinity,
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
createImage();
},
child: const Text("create"),
),
);
}
createImage() async {
final stopWatch = Stopwatch();
stopWatch.start();
debugPrint("tim0 ${DateTime.now()}");
BuildContext? buildContext = sharePageKey.currentContext;
if (null != buildContext) {
RenderRepaintBoundary boundary =
buildContext.findRenderObject() as RenderRepaintBoundary;
ui.Image image = await boundary.toImage(pixelRatio: 5);
ByteData? byteData =
await image.toByteData(format: ui.ImageByteFormat.png);
if (byteData != null) {
var pngBytes = byteData.buffer.asUint8List();
debugPrint("time elapsed in (ms) = ${stopWatch.elapsedMilliseconds}");
}
stopWatch.stop();
}
}
}
logs(Android stable 3.0.3) Roughly 1.5 secs
logs(ios flutter 3.0.3 stable/ 3.1.0 master) takes around 3-3.2 secs
logs (ios) stable 2.10.5 takes 700-800ms
flutter doctor -v (mac)
|
Image.toByteData()
is super slow on Flutter 3
This started with a change to the engine's thread priorities (flutter/engine@5140a44) The image encoding work is done on the IO thread, which is configured with a reduced priority. Is anyone seeing significant issues on a real device? Or is this only affecting iOS simulators? |
iPhone XR , iPhone x, and iPhone 13, These are my real devices,and test in release mode. |
In addition, it seems that the release mode is slower than the debug mode, and in the debug mode, it is not necessarily slow every time, but most of the time. |
Very slow for iOS devices in release mode :( |
This is a duplicate of #107351 which is under discussion. Fixing that will resolve this as well. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
image.toByteData
time consuming in flutter 2.10.5 and flutter 3.0.3, only in iOSSteps to Reproduce
flutter run
on the code sampleExpected results: The total time should be about the same
Actual results: 847ms and 8942ms, nearly eight times the difference! Even the real machine in release runs very very slow,eight times the difference!.
Code sample
Logs
The text was updated successfully, but these errors were encountered: