Ever wondered how your iOS app size is calculated. In this blog, we will see how I measured one of my apps and optimised its size.
(for an already published app, we can easily get app size using iPhone/iPad App Store)
(If the app is submitted and processed by Apple in AppStore Connect)
With the help of Xcode archive, we can get an approximate size of the app before submitting to the App Store Connect
How to check approximate App store size of app in Xcode
Note
This is not the final size. It may be larger in the app store when the app is approved and published. That is because the .ipa file submitted to iTunes will be processed with DRM by Apple. DRM encrypts the .ipa file to prevent app piracy & again recompressing the .ipa file.
Apple’s DRM is known as FairPlay
app_name.app/app_name
) must not exceed these limits:MinimumOSVersion
is less than 7.0: maximum of 80 MB for the total of all __TEXT
sections in the binary.MinimumOSVersion
is 7.x through 8.x: maximum of 60 MB per slice for the __TEXT
section of each architecture slice in the binary.MinimumOSVersion
is 9.0 or greater: maximum of 500 MB for the total of all __TEXT
sections in the binary.these checks can be done using this Viewing Virtual Memory Usage.
For example: Look at the Telegram app and see how much each file type contributes and what are they?
The binaries (the main binary, frameworks, and extension binaries). Binaries usually make up 60%+ of an app’s download size. Then followed by assets like images, audio files, fonts, etc.,
As the features within an app grow, there will be an increase in resources, class files. But we never revisit to clear the unused assets. The manual way for this:
LSUnusedResources is a cool open-source tool that helps us to do this task easily.
There are three main aspects of App Thinning: App Slicing, Bitcode, and On-Demand Resources.
Before iOS 9, Apple used a universal binary that means same binary will be downloaded in all the devices. This unnecessarily included the assets needed for a particular device model.
So to overcome this apple came with a technique called App Slicing, we can upload a single ipa to the apps store connect and apple will slice it to different IPA's according to the executable architecture and resources that are needed for the target device
This process is completely done by the Apps Store. We can use TestFlight and Xcode for testing this.
Bitcode is an intermediate representation of a compiled program. Apps you upload to iTunes Connect that contain bitcode will be compiled and linked on the App Store.
What's the need to enable bitcode in the app?
Apple is continuously enhancing the optimization performed by the Clang compiler to further improve the performance of mobile applications and reduce its size.
Using the embedded bitcode, Apple itself can recompile applications using the latest, improved version of the compiler. This not only frees app developers from the burden of continuously having to update their development environment but also recompile & re-upload their applications to benefit from the latest improvements.
The embedded bitcode enables Apple to recompile existing applications and make them compatible with the chipsets of new devices.
Note
ODR is a technique to reduce the initial download size of applications which rely on large assets for use. This is especially useful to games developers with large assets only required during certain stages of the game.
Smaller app with the tagged sets of resources hosted on the App Store, Courtesy: Apple doc
Benefits of On-Demand Resources:
Every time when we push an app update to the app store, the user will not be downloading the entire app again & again. Instead, Apple will create an update package and send it to the user via the app store.
So, we need to make sure we did not push any unwanted changes in storyboards and xibs and frameworks etc.
LLVM provides 5 optimization levels (Apple Clang Code Generation) they are:
When creating a new project in Xcode it sets up 2 configurations with following default values for the LLVM optimization levels:
Debug:
-O0 (none) - the fastest compile-time, the easiest debugging
Release:
-Os (fastest, smallest) - the best combination of small binary size and fast runtime execution
Swift provides three different optimization levels (Swift Compiler Code Generation):
-Onone
: Used while Development. Performs minimal optimizations and preserves all debug info.-O
: This is meant for most production code. The compiler performs aggressive optimizations that can drastically change the type and amount of emitted code. Debug information will be emitted but will be lossy.-Osize
: This is a special optimization mode where the compiler prioritizes code size over performance.Make sure you understand each of this setting and configure your project according to the requirement. The recommend for release version is Fastest, Smallest [-Os]
and -Osize
Please let me know in the comments if you have any other techniques to optimise the app size.
I would like to thank my ex-colleague and friend David Clements to make me understand the importance of customer first
in everything we design and develop.
This is a free third party commenting service we are using for you, which needs you to sign in to post a comment, but the good bit is you can stay anonymous while commenting.