这段时间对Microsoft Edge for iOS进行了瘦身,总结如下。
TL;DR
- 关于Edge for iOS的一些背景
- 主要语言是Swift, 所以不可避免的有Swift的8MB问题
- 项目使用Cocoapods管理依赖,倾向于使用静态库而非动态库
- 因为项目原因有一些必要依赖无法避免
- 本文列举了在进行包优化的过程中所使用的一些方法/工具,其中效果显著的步骤加粗显示 (主要是清除多余文件/资源,动态库转静态库)
- 原文以英文内部邮件的形式发出,这里将原文脱密后附录如下
Why app size matters?
- 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
- 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
- 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
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
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
- 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
- Find and remove unused class
- Find and remove unused code
Analyze assets
- Find and remove unused assets
- Find and remove duplicate files
- Remove extra fonts
- Move on-demand resources to cloud
- Compress resources: Image, Video/Audio
Analyze dependencies
- Move Cocoapods dependencies from dynamic framework to static libraries
- Ensure dependencies are correctly built for release mode and resources compressed
- Remove unneeded dependencies
What’s next?
There’re some potential optimization methods which need more efforts, we’re actively evaluating their feasibilities
- Use 8-bit PNG instead of 32-bit PNG
- Replace small images with inline code
- Compress JavaScript/html
- Remove duplicate strings
- Turn off C++/Objective-C exception support in Xcode