Skip to main content

How to reduce your iOS app size: 4 tips

SBM blog CTA mobile 1

Boost ops efficiency, drive revenue, & save big with omnichannel messaging

In addition to maintaining high uptime and low latency for any service, it’s crucial to have an iOS app that doesn’t crash and doesn’t take up a lot of space on users’ devices. At Sendbird, we understand that our iOS chat SDKs and calls SDKs can affect the apps that use them. We take steps to ensure that this doesn’t negatively impact the end user’s experience.

Purple gradient

Your app, your data. Drive engagement, conversion, & retention with the most trusted chat API.

Why iOS app size is important

Unlike before, the app UI and app UX are richer and have more features. Since phones are becoming more performant every year, there’s a lower need for developers to make apps as compact. This implies the possibility of more images, audio, video files, and animations in the apps. For example, modern apps may have a rich in-app chat UX or high-quality in-app calls.

While this is generally acceptable for people who use high-end (and expensive) devices, it is worthwhile to consider the users who may struggle with low device storage. It is widely known that people are more likely to delete larger apps, and in many places in the world, high-end devices are not the norm. In this blog, we'll discuss how we reduced our iOS SDK size by 30%.

Ebook Grow background mobile
Create deeper connections & boost customer engagement with in-app calls

Reducing your iOS app size or IPA file size

4 steps to reduce your iOS app size

Reducing the size of an iOS app or IPA file involves a combination of strategies that focus on optimizing code, managing assets, leveraging build tools, and adhering to efficient coding patterns. Here’s a deep dive into the techniques we used to significantly reduce the size of our iOS SDK.

1. Code refactoring to reduce IPA file size

Code refactoring is one of the most effective ways to reduce the binary size since it can directly impact the lines of code that end up in the final binary. When refactoring, it is important to reorganize and optimize existing code without changing the program's behavior. Here are 3 strategies we adopted to achieve this:

  1. Eliminated redundant code: We identified and removed duplicate code. We also consolidated similar functionality into single reusable components. For example, we merged multiple JSON serialization objects into one, reducing overhead.

  2. Optimized data structures: We replaced complex data structures with more efficient alternatives. For instance, using lightweight structs instead of classes where appropriate can save memory and reduce the binary size.

  3. Inlining functions: While inlining can increase code size, strategic inlining of small functions can reduce the overhead associated with function calls. We were cautious in avoiding excessive inlining, especially in frequently used or large functions.

2. Compiler optimization to reduce IPA file size

Compiler optimizations can significantly reduce the final binary size. While the compiler always has some internal processes that reduce the final binary sizes, we also enabled specific flags to enforce more strict behavior in the compiler to optimize for size. Here are a few optimization techniques that we leveraged:

  1. Dead code stripping: This process removes code that is never executed. Compilers like LLVM are quite sophisticated in detecting and stripping out dead code paths. We ensured that our build settings enabled this optimization, resulting in a smaller binary.

  1. Link-time optimization (LTO): LTO allows the compiler to perform optimizations across all files at link time, rather than just within individual files. This can lead to more aggressive optimization opportunities and a smaller binary.

  1. Whole-module optimization: This optimization compiles the entire module as a single unit, enabling the compiler to perform optimizations across the entire module, resulting in more efficient code and reduced binary size.

3. iOS library dependency management to reduce IPA file size

Managing external dependencies effectively is crucial for keeping the app size in check:

We regularly reviewed our dependencies to identify unused or redundant libraries. Tools like CocoaPods and Carthage make it easy to manage dependencies, but it’s essential to ensure that each dependency is necessary. Internally at Sendbird, we try to minimize the number of dependencies in our chat SDKs and calls SDKs, and replace them with a simpler internal implementation when possible. This helps us reduce extraneous features that dependencies offer and keep the size of our iOS SDK down.

4. Efficient iOS coding patterns

Adhering to efficient coding patterns can have a substantial impact on app size.

  1. Class vs. struct: In Swift, structs are value types, and classes are reference types. Structs are generally more memory efficient because they don’t involve heap allocation and reference counting. Use structs for small, simple data containers that don’t require inheritance or identity.

  1. Using `final` keyword: Marking classes with the `final` keyword prevents them from being subclassed. This allows the compiler to perform optimizations that reduce the overhead associated with dynamic dispatch.

  1. Using `static` functions over `class` functions: One of the differences between `static` and `class` functions is that `class` functions can be overridden in subclasses, while `static` functions cannot. This means that `class` functions require dynamic dispatch, which is determined at runtime. In contrast, static functions have static binding, determined by the compiler, and can be optimized further.

  1. Avoiding excessive generics: While generics can make your code more flexible and reusable, excessive use can lead to code bloat. Use generics judiciously, and prefer concrete types where performance and size are critical considerations.

Continuously monitoring IPA file size

As important as it is to reduce the IPA file size, it is also important to monitor it regularly to check for any increase. The IPA file size may increase with every incremental change in the codebase, so it’s critical to integrate a continuous monitoring system.

For this, we chose Emerge Tools. Emerge Tools is a powerful app size analysis tool that we integrated into our workflow. It allows us to monitor changes in app size across different builds and identify areas that contribute most to the size. By uploading our app to Emerge Tools, we get a detailed breakdown of the size contribution from each package and file. This continuous monitoring is crucial for maintaining a lean app over time, especially as new features are added.

Take a look at how we reduced our Android app size with Emerge tools.

iOS app size optimization results

Our IPA file size optimization efforts have already yielded significant results. The iOS SDK size was reduced from 2.8 MB to 2.0 MB, a 30% reduction. This happened without compromising any functionality, and our test cases and QA process heavily tested every change.

Don’t wait to reduce your iOS app size

Reducing the IPA file size is a multifaceted challenge that requires a combination of tools, techniques, and disciplined practices. By continuously monitoring IPA file size, refactoring code, leveraging compiler optimizations, managing assets, and modularizing our SDK, we’ve made substantial progress in creating leaner, more efficient apps. 

For fellow iOS developers, adopting these strategies can lead to significant IPA file size reductions, enhancing iOS app performance and user satisfaction. Remember, a smaller app not only provides a better user experience but also reaches a wider audience, especially in regions where device storage is limited.

This is especially useful when building efficient apps with high-quality and highly performant customer engagement tools such as in-app chat, calls, Business Messaging, or AI chatbots. Sendbird's global customer communication platform provides infrastructure that covers regions with intermittent network coverage and covers basic, low-budget devices. With an edge network to ensure low latency in communication, Sendbird ensures that customer communication needs are fulfilled regardless of the network connection and device performance. Contact us to learn more, or start building customer communications in your app right away.

Graident background

Build & deploy a custom AI chatbot in minutes for free

Ebook Grow background mobile

What are the preferred communication channels of modern customers?