App thinning checklist

这段时间对Microsoft Edge for iOS进行了瘦身,总结如下。

TL;DR

  1. 关于Edge for iOS的一些背景
    • 主要语言是Swift, 所以不可避免的有Swift的8MB问题
    • 项目使用Cocoapods管理依赖,倾向于使用静态库而非动态库
    • 因为项目原因有一些必要依赖无法避免
  2. 本文列举了在进行包优化的过程中所使用的一些方法/工具,其中效果显著的步骤加粗显示 (主要是清除多余文件/资源,动态库转静态库)
  3. 原文以英文内部邮件的形式发出,这里将原文脱密后附录如下

Why app size matters?

  1. Apple App store cellular download limit is 150 MB, which means app with compressed size over that limit can only be downloaded in WIFI environment
  2. Data from Google play, for every 6 MB increase to app size, we see a decrease in the install conversion rate of 1%: https://medium.com/googleplaydev/shrinking-apks-growing-installs-5d3fcba23ce2

What we have done to reduce app size?

Measure app size

  1. There’re two types of app size
    • Download size: This is the compressed size of the app downloaded over the air. This is also what we’re trying to optimize
    • Install size: This is the amount of disk space the app will take up on the customer’s device. This is also what user sees on App store

image source: https://stackoverflow.com/questions/35504571/is-ios-app-store-over-the-air-download-limit-based-on-download-size-or-instal

  1. Inspect ipa files to examine the compressed size of each item in the .ipa file
    unzip -lv {app}.ipa

    image source: https://stackoverflow.com/questions/52422675/how-to-extract-contents-from-a-ipa-file

  2. Leverage LinkMap to analyze the composition of main executable file

image source: https://github.com/kobe1941/shell

Monitor daily build size change

We have integrated our package size report into our CI and it will auto generates report and mail alert

Analyze code

  1. Ensure Xcode build setting is correctly configured
    • Optimization Level: Fastest, Smallest
    • Deployment Postprocessing: Yes
    • Strip linked Product: Yes
    • Symbols Hidden by default: Yes
    • Make Strings Read-only: Yes
  2. Find and remove unused class
  3. Find and remove unused code

Analyze assets

  1. Find and remove unused assets
  2. Find and remove duplicate files
  3. Remove extra fonts
  4. Move on-demand resources to cloud
  5. Compress resources: Image, Video/Audio

Analyze dependencies

  1. Move Cocoapods dependencies from dynamic framework to static libraries
  2. Ensure dependencies are correctly built for release mode and resources compressed
  3. Remove unneeded dependencies

What’s next?

There’re some potential optimization methods which need more efforts, we’re actively evaluating their feasibilities

  1. Use 8-bit PNG instead of 32-bit PNG
  2. Replace small images with inline code
  3. Compress JavaScript/html
  4. Remove duplicate strings
  5. Turn off C++/Objective-C exception support in Xcode
Thank you for making the world a better place!