Reputation: 821
Accoding to Flutter's build modes,
Compilation is optimized for fast startup, fast execution, and small package sizes.
What exactly does optimizing for small package sizes mean?
For web apps, the doc states:
The build is minified and tree shaking has been performed.
Does Flutter perform dead-code elimination on Dart code for Android/iOS when building the app in release mode? If so, how?
Comment: When analyzing the generated Android release apk
using Deeper analysis in DevTools
, it seems that dead code is not included. So at least for Android, it seems that Flutter performs dead-code elimination in release mode.
Upvotes: 19
Views: 8022
Reputation: 2187
Yes you are right with your assumption that dart performs within its release build tree shaking which can dramatically reduce the size of the app.
Here is the official explanation from the flutter team for the Release App Build:
Release: Use release mode for deploying the app, when you want maximum optimization and minimal footprint size. For mobile, release mode (which is not supported on the simulator or emulator), means that: Assertions are disabled. Debugging information is stripped out. Debugging is disabled. Compilation is optimized for fast startup, fast execution, and small package sizes. Service extensions are disabled.
Release mode for a web app means that: The build is minified and tree shaking has been performed. The app is compiled with the dart2js compiler for best performance.
You can read more about it within the following link: https://flutter.dev/docs/testing/build-modes
Upvotes: 5
Reputation: 746
I also wonder if dart compiler (not just flutter) does the tree shaking or not. In release mode, Flutter doc only mentions: Compilation is optimized for fast startup, fast execution, and small package sizes.
I think if they don't mention tree shaking here, it means the optimization doesn't have this feature.
But this article says yes: https://medium.com/flutter-community/excluding-dart-code-from-the-release-compiled-executable-7af8c18cd241
It would be nice if someone can give an official link about this.
Add information about code optimization for Android:
I don't see any information about tree shaking for iOS and linux:
Upvotes: 7