iOS App size reduction best practice

kumaresh
5 min readApr 6, 2023

--

Here I will give a piece of knowledge about how I reduced my app size from 120Mb to 69Mb and what are all the steps i have followed.

Why App Size is Important.

App size is important for several reasons, and understanding its importance can help both app developers and users

Firstly, app size can affect how quickly an app can be downloaded and installed by users. Users may be less likely to download an app if it takes up too much space on their device or if it takes a long time to download. This can have a negative impact on the app’s popularity and user base.

Secondly, app size can also impact the performance of the app. Large apps may require more resources and processing power to run, which can result in slower performance, longer load times, and decreased battery life. This can lead to a poor user experience and potentially negative reviews.

Thirdly, app size can also affect the cost of developing and maintaining an app. Larger apps may require more development resources and storage space, which can increase development costs and ongoing maintenance costs.

Therefore, it’s important for app developers to consider app size when designing and developing their apps. By optimizing app size, developers can improve the user experience, and increase the likelihood of downloads.

Size Optimization:

There are different types of practice are available on iOS. Listed below

Identify your app size:

First of all, you need to identify your app size.

Check your app size on App store or App Store Connect portal.

  • Login App Store connect and select your application
  • Go to the Test Flight section and select the build
  • Click the Build Metadata
  • In General Information section you can see Compressed File Size option
  • In that click App Store File Sizes

Below I have attached my app size screenshot before app size reduction.

App Size before size reduction

Steps to reduce app Size

1. Clean up the unwanted Image assets and files.

Cleaning the unwanted or unused files will project look like neat and clear

  • Identify the unused assets, storyboard, and files.
  • Try to use the HEIF format for images, and the HEVC format for videos
  • If you’re using PNG files, consider using 8-bit instead of 32-bit PNGs
  • Try to use 1x, 2x, and 3x images on image assets. so that Xcode will take the images based on the device

Use App Slice

Define a resizable center area of an image with optional end caps to reduce its size

  • Select the images on the image asset
  • Then click Editor > Show Slicing
  • Click the Start Slicing button that is displayed over the center of the image.
  • Click the appropriate button for the slicing operation you want to perform — horizontal, vertical, or both horizontal and vertical.
  • Use the Zoom In and Zoom Out buttons to increase or decrease the magnification of the image.

2. App Thinning

App thinning is a technique used in Xcode to optimize the size of the iOS app bundle that is delivered to users. This technique involves creating a package that contains only the resources that are necessary for a particular device or configuration. This helps to reduce the overall size of the app

  1. Archive your app in Xcode.
  2. Export your archived app as an Ad Hoc, Development, or Enterprise build.
  3. In the sheet for setting the development distribution options, choose “All compatible device variants” for app thinning.
  4. Sign your app and export it to your Mac.
  5. This process will create the folder which contained the IPA files for each variant of your app

Note: App thinning will work on development. ad-hoc and enterprise build option.

3. Use on-demand resources:

On-demand resources is a feature in Xcode that allows you to reduce the size of your app by delivering resources to users on demand.

You can ensure that only the resources required for a particular device or configuration are downloaded, which can reduce the overall size of your app and improve download times.

  • Click project target and select Resource Tags
  • Add for your bundle (i.e Dashboard) and add assets\
let tags = ["tagName"]
let request = NSBundleResourceRequest(tags: tags)

request.beginAccessingResources { error in
guard error == nil else {
// Handle the error here
return
}
// Access the resources here
}

4. BitCode Enable

Bitcode is an intermediate representation of an app’s compiled code that can be re-compiled by the App Store after the app is submitted

Enable bit code in build settings.

  1. Enabling bitcode can improve your app’s chances of being optimized by the App Store. When your app is submitted to the App Store with bitcode, the App Store can optimize the app’s code for specific devices, operating systems, and processor architectures. This optimization can reduce the size of the app that is downloaded by users, which can improve download times and reduce storage requirements.
  2. If your app uses third-party frameworks, enabling bitcode can ensure that those frameworks are also optimized by the App Store. This can reduce the overall size of your app and improve its performance.

Note: From Xcode 14 bitcode future is deprecated from xcode.

5. LLVM (Low Level Virtual Machine)

Xcode to compile source code for iOS, macOS, watchOS, and tvOS applications using LLVM.Xcode includes the Clang front-end, which is based on LLVM, and the LLVM back-end, which generates machine code for the target architecture.

LLVM provides the five optimization level.

  • None (-O0): This corresponds to the O0 optimization level in LLVM and disables all optimizations.
  • Fast (-O1): This corresponds to the O1 optimization level in LLVM and enables basic optimizations that do not significantly increase compile time.
  • Faster (-O2): This corresponds to the O2 optimization level in LLVM and enables more aggressive optimizations that may increase compile time.
  • Fastest (-O3): This corresponds to the O3 optimization level in LLVM and enables even more aggressive optimizations that may significantly increase compile time.
  • Fastest, Smallest: Optimize for size. This setting enables all Faster optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size. [-Os]
  • Fastest, Aggressive Optimizations: This setting enables Fastest but also enables aggressive optimizations that may break strict standards compliance but should work well on well-behaved code. [-Ofast]
  • Smallest, Aggressive Size Optimizations: This setting enables additional size savings by isolating repetitive code patterns into a compiler generated function. [-Oz]

Finally, our application size was reduced from 122 MB to 86.3 MB

Cheers 🥂 🍻

Keep Coding…👨🏻‍💻👨🏻‍💻👨🏻‍💻👨🏻‍💻👨🏻‍💻

--

--