Skip to content
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 still super slow on Flutter 3.3.7 #114788

Closed
fullflash opened this issue Nov 7, 2022 · 8 comments
Closed

[IOS] Image.toByteData() is still super slow on Flutter 3.3.7 #114788

fullflash opened this issue Nov 7, 2022 · 8 comments
Labels
in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds

Comments

@fullflash
Copy link

fullflash commented Nov 7, 2022

await image.toByteData(format: ImageByteFormat.png);

After Flutter 3 update it becames SUPER slow on ios. on android it works super fast
on each flutter new version it gets worst.

Flutter 3.3.7 android 7000 ms

Flutter 3 19000ms
Flutter 3.3.7 29000ms

Flutter (Channel stable, 3.3.7, on macOS 12.6.1 21G217 darwin-x64, locale
    en-TR)
    • Flutter version 3.3.7 on channel stable at /Users/****/SDK_all/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision e99c9c7cd9 (5 days ago), 2022-11-01 16:59:00 -0700
    • Engine revision 857bd6b74c
    • Dart version 2.18.4
    • DevTools version 2.15.0

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.2

there was an issue that was closed but no fixes still.
#106773

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Nov 7, 2022
@darshankawar
Copy link
Member

@fullflash
Can you provide complete minimal code sample that show the reported behavior ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Nov 7, 2022
@esDotDev
Copy link

esDotDev commented Nov 8, 2022

@fullflash Can you provide complete minimal code sample that show the reported behavior ?

An example was already shown in the previous issues that seems to have been incorrectly closed. It has significant details like benchmarks times, and additional discussion.

Maybe consider re-opening it? It's quite frustrating to developers when they take the time to log proper details about a bug, it is closed prematurely, then they are asked to provide details again about the same issue:
#106773

import '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();
    }
  }
}

@darshankawar
Copy link
Member

darshankawar commented Nov 9, 2022

Thanks for the feedback @esDotDev. Using code sample provided above, I do see difference in stable version as compared to master, but it is not the same / close to what OP mentioned:

Flutter 3 19000ms
Flutter 3.3.7 29000ms

Below are the numbers I got running on iOS simulator:

  1. Master (3.5.0-12.0.pre.175):
Syncing files to device iPhone 13 Pro...
flutter: tim0 2022-11-09 10:57:58.219414
flutter: time elapsed in (ms) = 676
flutter: tim0 2022-11-09 10:58:03.175285
flutter: time elapsed in (ms) = 1418
flutter: tim0 2022-11-09 10:58:15.377305
flutter: time elapsed in (ms) = 1277
flutter: tim0 2022-11-09 10:58:36.643482
flutter: time elapsed in (ms) = 1164
flutter: tim0 2022-11-09 10:58:41.807146
flutter: time elapsed in (ms) = 1145
flutter: tim0 2022-11-09 10:58:45.692196
flutter: time elapsed in (ms) = 1138
  1. Stable (3.3.7):
Syncing files to device iPhone 13 Pro...
flutter: tim0 2022-11-09 11:20:20.674216
flutter: tim0 2022-11-09 11:20:25.107674
flutter: time elapsed in (ms) = 4648
flutter: tim0 2022-11-09 11:20:28.141560
flutter: time elapsed in (ms) = 4828
flutter: tim0 2022-11-09 11:20:31.784351
flutter: time elapsed in (ms) = 6339
flutter: tim0 2022-11-09 11:20:36.499090
flutter: time elapsed in (ms) = 7241
flutter: tim0 2022-11-09 11:20:42.030696
flutter: time elapsed in (ms) = 7112
flutter: tim0 2022-11-09 11:20:46.117686
flutter: time elapsed in (ms) = 6113
flutter: time elapsed in (ms) = 6584

Below are the numbers from stable version running on physical device (iphone 6s) which as compared to above are significantly less.

Syncing files to device Darshan's iphone...
flutter: tim0 2022-11-09 11:40:46.356510
flutter: time elapsed in (ms) = 1908
flutter: tim0 2022-11-09 11:40:49.771682
flutter: time elapsed in (ms) = 1607
flutter: tim0 2022-11-09 11:40:52.737435
flutter: time elapsed in (ms) = 1558
flutter: tim0 2022-11-09 11:40:55.747225
flutter: time elapsed in (ms) = 1542
flutter: tim0 2022-11-09 11:40:58.638807
flutter: time elapsed in (ms) = 1558
flutter: tim0 2022-11-09 11:41:01.555304
flutter: time elapsed in (ms) = 1529
flutter: tim0 2022-11-09 11:41:04.271916
flutter: time elapsed in (ms) = 1563
flutter: tim0 2022-11-09 11:41:07.539790
flutter: time elapsed in (ms) = 1550

Can you share the variance you are seeing ? Based on that we can decide to reopen the original issue.

@esDotDev
Copy link

esDotDev commented Nov 9, 2022

Nice, so it seems like the issue has been fixed on master? 3.3.7 is still extremely slow, but at least a fix is coming :)

@ssyzh
Copy link

ssyzh commented Nov 21, 2022

flutter/engine#34568 solved the issue, but the stable branch was not merged, so I had to spend four months at 2.10.5.

@ssyzh
Copy link

ssyzh commented Nov 23, 2022

flutter/engine#34568 solved the issue, but the stable branch was not merged, so I had to spend four months at 2.10.5.

Very strange. In 3.3.8, the pull request is not merged, but the speed has been improved.

@github-actions
Copy link

github-actions bot commented Dec 5, 2022

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
Thanks for your contribution.

@github-actions github-actions bot closed this as completed Dec 5, 2022
@github-actions
Copy link

github-actions bot commented Mar 5, 2023

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 flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in triage Presently being triaged by the triage team waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds
Projects
None yet
Development

No branches or pull requests

4 participants