Rxswift: Binary size too large

Created on 13 Jan 2017  路  5Comments  路  Source: ReactiveX/RxSwift

Hello,

First of all thanks for such library. My app size grew a lot and when i tried to find out the problem I saw my generated ipa file.

My :

  • app size is 77 MB
  • ipa size is 177MB
  • frameworks folder in ipa 106 MB
  • Alamofire.framework is 5.5MB
    but
  • RxSwift 8.8MB and RxCocoa is 5.6 MB

I am using RxSwift from cocopods as :
pod 'RxSwift', '~> 3.0.1'
pod 'RxCocoa', '~> 3.0.1'

App is for IOS >= 9

using single xcode version 8.2.1 and Swift 3.0.1

What can i do to reduce binary size of framework?

Best Regards

Most helpful comment

Hi @kzaher ,

TL;DR;
When bitcode disabled and always embed swift is disabled, the difference is 4 MB.
Never enable bitcode :)

Long Journey
I know about app thinning thanks for reminding. On weekend i made a test with my pet project which has no image except the app icon. I uploaded it to TestFlight with and without Rx to test your theory. Here is the results in TestFlight:

I just added to Podfile these lines :
pod 'RxSwift', '~> 3.1.0'
pod 'RxCocoa', '~> 3.1.0'

And just imported in AppDelegate :
import RxSwift
import RxCocoa

There is no other change. Project is not using Rx in anywhere at all.

First results were pretty confusing; sometimes added 20 MB sometimes 9MB. I made many tests so i use sometimes :) Here is just one result with 9MB difference (the best i got) :

with Rx :

  • Compressed file size : 81,2 MB
  • iPhone6s size : 43,2 MB

without Rx :

  • Compressed file size : 73,0 MB
  • iPhone6s size : 34,0 MB

Then i wanted to try something else; removing bit code support and setting always embed swift binaries to false. Results are funny:

with Rx :

  • Compressed file size : 44,9 MB
  • iPhone6s size : 18,3 MB

without Rx :

  • Compressed file size : 41,9 MB
  • iPhone6s size : 14,3 MB

Rx is costing 4MB at least

I especially shared this to help others who may encounter same problem.

All 5 comments

Hi @ergunkocak ,

I don't think this is the amount of data that will be sent to end user on each app download.

There is a mechanism called app thinning.

https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AppThinning/AppThinning.html

You also need to zip the framework contents.

I think that RxSwift should be ~1.3MB and RxCocoa ~0.8MB zipped after app thinning.

That's about the size of two jpeg images in 3x resolution.

If you want to further reduce the file size you can fork the library and remove files that you think you don't need.

Hi @kzaher ,

TL;DR;
When bitcode disabled and always embed swift is disabled, the difference is 4 MB.
Never enable bitcode :)

Long Journey
I know about app thinning thanks for reminding. On weekend i made a test with my pet project which has no image except the app icon. I uploaded it to TestFlight with and without Rx to test your theory. Here is the results in TestFlight:

I just added to Podfile these lines :
pod 'RxSwift', '~> 3.1.0'
pod 'RxCocoa', '~> 3.1.0'

And just imported in AppDelegate :
import RxSwift
import RxCocoa

There is no other change. Project is not using Rx in anywhere at all.

First results were pretty confusing; sometimes added 20 MB sometimes 9MB. I made many tests so i use sometimes :) Here is just one result with 9MB difference (the best i got) :

with Rx :

  • Compressed file size : 81,2 MB
  • iPhone6s size : 43,2 MB

without Rx :

  • Compressed file size : 73,0 MB
  • iPhone6s size : 34,0 MB

Then i wanted to try something else; removing bit code support and setting always embed swift binaries to false. Results are funny:

with Rx :

  • Compressed file size : 44,9 MB
  • iPhone6s size : 18,3 MB

without Rx :

  • Compressed file size : 41,9 MB
  • iPhone6s size : 14,3 MB

Rx is costing 4MB at least

I especially shared this to help others who may encounter same problem.

@kzaher one question though how can i zip framework contents? I want to test that too

Cheers

Hi @ergunkocak ,

Maybe I'm wrong about this, but not sure why are you getting those results.

Here is something you can try as a sanity check.

Build Rx in release mode with optimizations turned on (any optimizations you fancy) for single architecture only and zip the contents.

That's how I got

I think that RxSwift should be ~1.3MB and RxCocoa ~0.8MB zipped after app thinning.

App you download from the App Store should already be zipped. That's approx 2MB for both.

It seems to me that in your case you might have downloaded two architectures (without bitcode).

Probably arm_v7 and arm64.

If you download binary from latest release https://github.com/ReactiveX/RxSwift/releases/tag/3.1.0 unzip the binaries and zip only RxSwift, you'll get ~10.2MB (all architectures with bitcode).

/Users/kzaher/Downloads/Carthage 2/Build/iOS/RxSwift.framework/RxSwift: Mach-O universal binary with 4 architectures: [i386: Mach-O dynamically linked shared library i386] [x86_64] [arm_v7] [arm64]
/Users/kzaher/Downloads/Carthage 2/Build/iOS/RxSwift.framework/RxSwift (for architecture i386): Mach-O dynamically linked shared library i386
/Users/kzaher/Downloads/Carthage 2/Build/iOS/RxSwift.framework/RxSwift (for architecture x86_64):   Mach-O 64-bit dynamically linked shared library x86_64
/Users/kzaher/Downloads/Carthage 2/Build/iOS/RxSwift.framework/RxSwift (for architecture armv7):    Mach-O dynamically linked shared library arm_v7
/Users/kzaher/Downloads/Carthage 2/Build/iOS/RxSwift.framework/RxSwift (for architecture arm64):    Mach-O 64-bit dynamically linked shared library arm64

If you do the same for RxSwift and RxCocoa, you'll get ~15.2 (all architectures with bitcode).

I can't figure out why it behaved that way in your measurements.

Anyway, not sure can do anything else right now except for remedies described previously in this thread.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hannesstruss picture hannesstruss  路  3Comments

trungp picture trungp  路  3Comments

lyricsboy picture lyricsboy  路  3Comments

acecilia picture acecilia  路  3Comments

jaumard picture jaumard  路  3Comments