Realm-cocoa: The size of `Realm.framework/Realm` becomes too big when built with Swift 3.1 in Xcode 8.3

Created on 28 Mar 2017  路  19Comments  路  Source: realm/realm-cocoa

I am using

  • Realm version: 2.4.4
  • Xcode version: 8.3
  • OSX version: 10.12.4
  • Dependency manager + version: Carthage 0.14.0

What's happening

After updating Xcode to 8.3, Swift 3.1, and Carthage builds by running carthage update realm-cocoa --platform ios --no-use-binaires, the size of Realm.framework/Realm becomes 155.50 MB. It was only 54 MB in Xcode 8.2, Swift 3.0.1.

I already tried below but wouldn't fix

  • clean up all the cache in Xcode
  • delete the existing build and build again

Problem

Because all the .framework built with Carthage are committed to the repository in my project, the size of each frameworks needs to be less than 100MB since GitHub's file size limit is 100MB. I want to make it smaller than that. Is there any suggestions or tricks to fix this problem?

Thank you!

T-Bug

Most helpful comment

To avoid the bitcode explosion issue present in Xcode 8.3, I'd suggest using a previous version of Xcode that produces binaries with smaller bitcode slices.

All 19 comments

I'm seeing the same result building master locally. The Swift and macOS frameworks are roughly the same size; it's only the iOS Realm.framework that's larger.

The __LLVM segment is now 70 MB in each of the device slices, so this does look like it's due to bitcode.

Alright, well there's no much we can do to alleviate that then.

rdar://31302382: Xcode 8.3 produces binaries 3x larger than Xcode 8.2 due to a 4x increase in bitcode

Sorry to comment on a closed issue.
Is this claim in the FAQ still correct:

Once your app is built for release, Realm should only add around one megabyte to its size.

?

No, that's incorrect. For example, if you look at the macOS framework, which only has a single architecture slice and no bitcode, it weighs in at 7MB.

And some quick checks would indicate that iOS slices are closer to 5.7MB for Realm Objective-C, 1.2MB for Realm Swift:

$ ./build.sh ios-swift
$ cd build/ios/swift-3.1
$ xcrun bitcode_strip -r Realm.framework/Realm -o Realm.nobitcode
$ xcrun bitcode_strip -r RealmSwift.framework/RealmSwift -o RealmSwift.nobitcode
$ lipo -thin arm64 RealmSwift.nobitcode -o RealmSwift.arm64
$ lipo -thin arm64 Realm.nobitcode -o Realm.arm64
$ size Realm.arm64
5.7M    Realm.arm64
$ size RealmSwift.arm64 
1.2M    RealmSwift.arm64

Thanks for bringing this to our attention. I've updated this section of our docs to reflect this information, it should be live momentarily.

@jpsim
Thanks for responding so quickly and updating the docs!

Does that mean I cannot include Realm in watchOS? It is now exceeding the 50MB limit.

The watchOS framework should just add 5.1MB to your app installed on user devices via the App Store. From the release archive:

$ lipo -thin armv7k Realm.framework/Realm -o Realm.armv7k
$ xcrun bitcode_strip -r Realm.armv7k -o Realm.armv7k.nobitcode
$ size Realm.armv7k.nobitcode 
5.1M    Realm.armv7k.nobitcode

That being said, would you know if bitcode counts towards that limit? We never got clarification on that in #3430.

I'm unable to upload new builds to iTunesConnect as it says my watchOS app is exceeding the limit. It is now 101 MB. Any tips?

To avoid the bitcode explosion issue present in Xcode 8.3, I'd suggest using a previous version of Xcode that produces binaries with smaller bitcode slices.

@jpsim I am actually seeing building with 8.2.1 still produce the same inflated sizes in iTunes Connect.

This seems to indicate a massive regression on Apple's end.

Facebook's app size on the AppStore is 320mb on a iPhone 7 Plus (and they just shipped the update today)

From the measurements I reported in rdar://31302382, Xcode 8.2.1 produces much smaller bitcode slices than 8.3. I haven't compared 8.2.1 with earlier versions to see if it also regressed.

To anyone else that needs an immediate resolution, you will have to disable bitcode as well as use Xcode 8.2.1 until this bug is fixed by Apple.

Our latest built was archived in Xcode 8.2.1 with bitcode enabled after Xcode 8.3 is out
We have RealmSwift in both iPhone and Watch
It does not inflate the Realm binary, and the sizes of variations range from 71.1MB to 72.4MB

I guess the problem only happens in Xcode 8.3

Where I can download XCode 8.2.1 now?

Does Xcode 8.3.1 solve the problem?

EDIT:
So I tested myself, Realm framework now becomes small, 1MB more than compiled in Xcode 8.2.x
but works

Yes, it should do.

Was this page helpful?
0 / 5 - 0 ratings