Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter app slow

Tags:

flutter

dart

I'm trying out Flutter and my app is responding very very slow on both the emulator and real device. I get warnings like this

Skipped 51 frames! The application may be doing too much work on its main thread.

I'm aware Dart is a single-threaded programming language and in Android I used to solve this with the good old new Thread(); block for async. I am trying to apply the same in Flutter and I reading through Future await async and the sorts but the examples seem to be addressing when you reading data from the internet. My app doesn't read anything online at this stage, I'm getting Skipped x frames when my screen has progress dialog, when I am opening a new screen/page, and with every animation on the app. Here is an example of the class where I am getting the issue:

_buildContent(){
    return new Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        new InkWell(
          onTap: (){
            Navigator.push(context, new MaterialPageRoute(builder:
                (context) => new LoginScreen()));
          },
          child: new Container(
            height: 150.0,
            width: 150.0,
            child: new Image.asset("images/logo.png", fit: BoxFit.cover,),
          ),
        ),
        new Container(
          margin: const EdgeInsets.all(16.0),
          child: new CircularProgressIndicator(
              value: null,
              strokeWidth: 1.0,
              valueColor: new AlwaysStoppedAnimation<Color>(
                  Colors.white
              )
          ),
        )
      ],
    );
  }

I'm assuming the skipped x frames warning is caused by the progress dialog? I have another screen (Login Screen) which animates widgets into place when opened, the animations move so slow, I can literally see each frame being rendered. Is there a tutorial online that can assist with addressing this or just understanding Dart's Asynchronous Programming?

like image 473
spongyboss Avatar asked May 09 '18 13:05

spongyboss


People also ask

How do I speed up my Flutter app?

Avoid Build Method Try to avoid using the Build() method as it is costly and consumes lots of CPU power. Repetitive use of Build() can decrease the Flutter performance. To get the best Flutter performance in your existing application, you can divide the large widgets developed with the Build() method into smaller ones.

Is Flutter slow?

The technology is rather slow, and causes a kind of slowdown. So, Flutter can be named a winner.

Is Flutter slower than native app?

The first thing these results make clear is that a native Android app trumps both the React Native and Flutter apps by a non trivial margin when it comes to performance.

Why Flutter run taking too long?

When flutter run is taking forever to initialize gradle it is probably due to network problem. Else, you might need to download gradle manually and install it. Downloading gradle manually is advisable especially if you are connected to extremely slow network.


3 Answers

debug mode

  • launch is slow
  • blink when launch
  • app size big.

because debug mode with Hot reloads.

when you create release apk https://flutter.io/docs/deployment/android

you can find

  • fast launch
  • no blink during the launch
  • app size small (but bigger than the normal android app)

EDIT

https://flutter.io/docs/testing/ui-performance#debug-flags

Debug mode enables additional checks (such as asserts) that don’t run in profile or release builds, and these checks can be expensive. Debug mode also executes code in a different way than release mode. The debug build compiles the Dart code “just in time” (JIT) as the app runs, but profile and release builds are pre-compiled to native instructions (also called “ahead of time”, or AOT) before the app is loaded onto the device. JIT can cause the app to pause for JIT compilation, which itself can cause jank.

https://github.com/flutter/flutter/wiki/Flutter%27s-modes

Debug mode on device (including simulators, emulators): Turns on all the assertions in the world, includes all debugging information, enables all the debugger aids (e.g. observatory) and service extensions. Optimizes for fast develop/run cycles. Does not optimize for execution speed, binary size, or deployment. Used by flutter run. Built with sky/tools/gn --android or sky/tools/gn --ios. Also sometimes called "checked mode" or "slow mode".

like image 95
changhao cui Avatar answered Oct 17 '22 13:10

changhao cui


Try running your app in release mode using flutter run --release in the terminal.

like image 29
Dyary Avatar answered Oct 17 '22 14:10

Dyary


Debug build has some performance issues, as many asserts and other validations happen in release build. Release build is much more faster than debug build.

Running app in release build may help. Try to run in release mode

flutter run --release
like image 11
prashant Avatar answered Oct 17 '22 14:10

prashant