Flutter-desktop-embedding: Release mode AOT

Created on 27 Sep 2018  路  6Comments  路  Source: google/flutter-desktop-embedding

Hi there,

I'm using the Linux embedder with the assets generated by a flutter build bundle, but the performance is not that great.

I'm noticing the Observatory is listening on a port, which tends to mean the app is starting in Debug mode (which is slower).

Also, whenever I first go to a new screen on the app it takes longer to load, which leads me to think the JIT compiler is being used (instead of AOT).

Is there a way to compile the app and have it run fast just like a flutter run --release would on Android?

Edit: I should probably mention the engine is compiled in release mode and optimized.

Thanks.

Most helpful comment

For anyone interested in exploring this, the new AOT instructions will likely be of interest.

I haven't experimented with this, and it's still not a priority for this project at the moment, but as noted above it if anyone does try it out, please let us know how it goes.

All 6 comments

but the performance is not that great.

Since you're on Linux, be aware that issue #58 may be a significant factor in that.

I'm noticing the Observatory is listening on a port, which tends to mean the app is starting in Debug mode

The Debug/Profile/Release configurations are a construction of the flutter tool, which doesn't support desktop, so can't be applied directly; the fact that the observatory is running on desktop just means you haven't passed --disable-observatory. If you're passing --dart-non-checked-mode, for instance, then your configuration no longer matches what the Flutter tooling for mobile calls "Debug". Given that, it's best in the context of this project to talk about specific settings rather than those configuration labels.

which leads me to think the JIT compiler is being used

This is true; flutter build is not capable of making AOT builds for desktop.

Is there a way to compile the app and have it run fast

You could try these instructions for doing AOT compilation of the Dart code, and then combining that with the results of flutter build bundle. However, note the discussion there: there's no guarantee that AOT will actually be faster than JIT for your use case.

Given issue #58, and that no attempt has been made yet to profile desktop Flutter performance and understand the current performance characteristics, I suspect focusing on AOT at this stage is premature. But if you decide to try it out I'd be interested to know what effects you find.

For anyone interested in exploring this, the new AOT instructions will likely be of interest.

I haven't experimented with this, and it's still not a priority for this project at the moment, but as noted above it if anyone does try it out, please let us know how it goes.

I have tried it (though not in this embedder, but a custom written one for the raspberry pi) and the instructions are quite easy. If you do it for x86 you'll have to use the manual path since the standard flutter build aot will pass flags on floating point methods, which will make the build fail on your machine. After generating, loading it is as simple as memorymapping the 4 files with the given flags, passing them to the engine config, and voila, it works :)

@RBogie after AOT, did you see improvements in startup time or used memory?

EDIT: Managed to compile the engine, generate AOT for macos64 and hack together custom FlutterMacOS that does mmap.

Could do print('hello world') but runApp(SizedBox()) would crash on Paragraph::Layout.

I managed to finally run my (simple) app in AOT. The crash was due to hacks I did with FlutterMacOS which were completely unnecessary.

The results are pretty good. AOT app takes less memory and and starts faster. If anyone wants to try, I'm attaching a link.

https://drive.google.com/open?id=12f0LGv1Uc4yn-OAqPrurcdXEvHdFpA3F

It is possible to setup Xcode project does usual build on Debug and AOT on Release. For this we need second FlutterMacOS.framework that loads executable images into memory and a script that builds these images.

Out of laziness I have embedded entire build folder into the apps which increased their size.

Moved to https://github.com/flutter/flutter/issues/30672 (generalized slightly to not pre-assume that AOT will definitely be the best solution for a release mode).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DavBfr picture DavBfr  路  9Comments

stuartmorgan picture stuartmorgan  路  5Comments

pmatteo1998 picture pmatteo1998  路  7Comments

icode picture icode  路  3Comments

iamsabet picture iamsabet  路  5Comments