TUM-Dev / campus_flutter

Development of the cross-platform TUM Campus App with Flutter - for and from students at Technical University of Munich.
https://tum.app/
GNU General Public License v3.0
37 stars 4 forks source link

[Enhancement] Optimize Application Size #173

Closed Garfield96 closed 8 months ago

Garfield96 commented 9 months ago

Is your feature request related to a problem? Please describe. The campus-flutter app currently has a size of ~80mb. Compared to the campus-android app (~29mb), this is very large. It would be beneficial to shrink the app size, to take up less space on the user device, to speed-up app downloads and, potentially, to improve the performance of the app itself.

Describe the solution you'd like The campus-android app uses proguard to shrink the binary. For Android builds, this would be also applicable to campus-flutter. There are several blog posts describing how to decrease binary size for flutter apps, which might also help.

Describe alternatives you've considered None

Additional context To keep the size under control, it would be possible to check the size in the CI and automatically add a comment to a new PR describing the increase/decrease in size.

jakobkoerber commented 9 months ago

We could try using proguard but I don't think it will affect the application size greatly since Flutter already uses tree shaking. The application size is mainly larger than Android since we use assets like a text classification model, videos and images. We could serve the text classification model via Firebase, but that adds imo a whole list of other issues/potential failure points

CommanderStorm commented 9 months ago

@Garfield96 in the age of basically free storage, free wifi and all phones having hundreds of GB of storage, and 100MB for an app being the average.

⇒ reduction not really necessary

kordianbruck commented 8 months ago

Here is some actual data from the android version:

 flutter build appbundle --analyze-size --target-platform android-arm 

Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 9264 bytes (99.4% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Running Gradle task 'bundleRelease'...                             88.8s
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
app-release.aab (total compressed)                                         55 MB
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  BUNDLE-METADATA/
    com.android.tools.build.libraries                                       5 KB
    com.android.tools.build.obfuscation                                   406 KB
  base/
    assets                                                                 32 MB
    dex                                                                     2 MB
    lib                                                                    21 MB
    Dart AOT symbols accounted decompressed size                           13 MB
      package:flutter                                                       4 MB
      package:syncfusion_flutter_calendar                                 756 KB
      package:campus_flutter                                              689 KB
      package:syncfusion_flutter_charts                                   460 KB
      dart:core                                                           439 KB
      dart:ui                                                             337 KB
      dart:typed_data                                                     323 KB
      package:syncfusion_flutter_datepicker                               317 KB
      package:flutter_localizations                                       252 KB
      dart:collection                                                     210 KB
      package:intl                                                        208 KB
      package:vector_graphics_compiler                                    194 KB
      dart:async                                                          163 KB
      dart:io                                                             156 KB
      package:syncfusion_flutter_core                                     153 KB
      package:http2                                                       128 KB
      package:hive                                                        121 KB
      package:protobuf                                                    119 KB
      package:xml                                                          90 KB
      package:vector_math                                                  87 KB
    manifest                                                                4 KB
    res                                                                    85 KB
    resources.pb                                                           79 KB
    root                                                                   13 KB
  META-INF/
    ANDROIDD.SF                                                            12 KB
    ANDROIDD.RSA                                                          1018 B
    MANIFEST.MF                                                             9 KB
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
A summary of your AAB analysis can be found at: /home/kb/.flutter-devtools/aab-code-size-analysis_01.json

To analyze your app size in Dart DevTools, run the following command:
dart devtools --appSizeBase=aab-code-size-analysis_01.json
✓ Built build/app/outputs/bundle/release/app-release.aab (55.3MB).
kordianbruck commented 8 months ago

So we could move the video to the backend and reduce the assets by 10MB. I think anything below 50 MB is reasonable.

kordianbruck commented 8 months ago

(https://docs.flutter.dev/perf/app-size has the docs on app size)

jakobkoerber commented 8 months ago

For iOS:

▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Runner.app                                                               86 MB
  Runner.app/
    GoogleMaps.bundle/
      bubble_left@3x.png                                                    2 KB
      bubble_left@2x.png                                                    1 KB
      bubble_right@3x.png                                                   2 KB
      bubble_right@2x.png                                                   1 KB
      GMSCoreResources.bundle                                               2 MB
      oss_licenses_maps.txt.gz                                            162 KB
      Assets.car                                                           43 KB
      GMSCacheStorage.momd                                                 16 KB
    AppIcon60x60@2x.png                                                     4 KB
    Runner                                                                 17 MB
    Base.lproj/
      Main.storyboardc                                                      3 KB
      LaunchScreen.storyboardc                                              5 KB
    Assets.car                                                            227 KB
    AppIcon76x76@2x~ipad.png                                                5 KB
    Frameworks/
      GoogleDataTransport.framework                                       363 KB
      FirebaseCrashlytics.framework                                       687 KB
      FBLPromises.framework                                               150 KB
      FirebaseCoreInternal.framework                                      329 KB
      video_player_avfoundation.framework                                 175 KB
      FirebaseCore.framework                                              174 KB
      FirebaseSessions.framework                                          337 KB
      GoogleUtilities.framework                                           130 KB
      Flutter.framework                                                    10 MB
      sqflite.framework                                                   127 KB
      FirebaseCoreExtension.framework                                      51 KB
      App.framework                                                        51 MB
      Dart AOT symbols accounted decompressed size                         13 MB
        package:flutter                                                     4 MB
        package:campus_flutter                                            702 KB
        package:syncfusion_flutter_calendar                               659 KB
        package:syncfusion_flutter_charts                                 418 KB
        dart:core                                                         374 KB
        dart:ui                                                           317 KB
        package:syncfusion_flutter_datepicker                             281 KB
        dart:typed_data                                                   272 KB
        package:flutter_localizations                                     268 KB
        package:intl                                                      200 KB
        dart:collection                                                   195 KB
        package:vector_graphics_compiler                                  180 KB
        dart:async                                                        170 KB
        dart:io                                                           157 KB
        package:syncfusion_flutter_core                                   142 KB
        package:http2                                                     123 KB
        package:protobuf                                                  110 KB
        package:hive                                                      102 KB
        package:xml                                                        94 KB
        dart:ffi                                                           88 KB
      map_launcher.framework                                              165 KB
      nanopb.framework                                                     59 KB
      url_launcher_ios.framework                                          140 KB
      Promises.framework                                                  178 KB
      device_info_plus.framework                                           56 KB
      path_provider_foundation.framework                                   94 KB
      flutter_secure_storage.framework                                    143 KB
      FMDB.framework                                                      158 KB
      FirebaseInstallations.framework                                     233 KB
      geolocator_apple.framework                                          123 KB
      flutter_native_splash.framework                                      71 KB
      package_info_plus.framework                                          56 KB
      shared_preferences_foundation.framework                             120 KB
    GoogleMapsResources.bundle/
      GoogleMaps.bundle                                                     2 MB
    Info.plist                                                              2 KB
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒