Realm-cocoa: Realm on the Apple Watch with a Swift project is not feasible

Created on 5 Aug 2017  路  17Comments  路  Source: realm/realm-cocoa

Goals

Using Realm on the Apple Watch with a Swift project is not feasible. You are limited to 50MB for your watch bundle, with the system and all the Swift libraries taking up 30MB of that, then Realm adding another 15MB. This leaves ~5MB for the actual application, including all assets.

Expected Results

It would be great to have a lightweight version of Realm that uses less than 5MB of space in a bundle. Even if it was readonly and require a pre-populated Realm database file. Not sure what other functionality could be trimmed to reduce the code size.

T-Help

Most helpful comment

That's hilarious, and makes no sense at all 馃槥

All 17 comments

You're absolutely right. It'd be interesting to measure the binary size reduction from avoiding the sync components, as I've started in #4851.

Thanks for the update. Looks like #4851 is on hold, do you have an ETA for it?

No.

Does the environment variable, REALM_DISABLE_SYNC=TRUE, work so I can at least test the theory to see how much we would save?

No, there are major changes required to the build system to avoid adding sync components contribute to binary size.

I'm curious how you've determined that Realm contributes 15MB to the application size. By my analysis, Realm should contribute 7MB. I found this figure by stripping out the simulator architecture and bitcode slice from the watchOS frameworks in our most recent release. That leaves me with a Realm.framework that's around 5.7MB and a RealmSwift.framework that's around 1.2MB.

Bitcode is unfortunately counted in the size limit in iTunesConnect.

That's hilarious, and makes no sense at all 馃槥

Sorry for the poor research, looks like this was already brought up a year ago
https://github.com/realm/realm-cocoa/issues/3430

Looks like Realm w/ Swift on the watch is not happening anytime soon.

Is it worth putting something in the FAQ or elsewhere in the docs so that developers are aware about the issue?

Ideally we'd add the rough numbers from the bitcode overhead to the size section of our FAQ, and point readers to a radar detailing how iTunesConnect shouldn't incorporate the bitcode weight in its size limit.

@jlaws would you be interested in filing such a radar?

FYI I am getting 18MB used by Realm/RealmSwift for submission to Apple.

You will probably be better off with the radar, coming from a larger organization, but I can file one as well so they know more people are concerned about it.

FYI I am getting 18MB used by Realm/RealmSwift for submission to Apple.

That's a bit surprising. My measurements indicate that Realm.framework & RealmSwift.framework should contribute ~26MB to a watch app with armv7k & bitcode slices:

$ curl -O https://github.com/realm/realm-cocoa/releases/download/v2.9.1/Carthage.framework.zip
$ unzip Carthage.framework.zip
$ cd Carthage/Build/watchOS
$ lipo -thin armv7k Realm.framework/Realm -o Realm.armv7k
$ lipo -thin armv7k RealmSwift.framework/RealmSwift -o RealmSwift.armv7k
$ size Realm.armv7k
23M  Realm.armv7k
$ size RealmSwift.armv7k
2.8M  RealmSwift.armv7k

You will probably be better off with the radar, coming from a larger organization, but I can file one as well so they know more people are concerned about it.

Past radars don't indicate that filers from Realm have had more success than filers from outside Realm. However, if you file one, I'd be happy to duplicate it if you cross-post it to Open Radar if you think it will help it get more visibility.

Interestingly enough, if I attempt to measure the size of _just_ the bitcode from Realm frameworks for the watchOS platform, I get closer to the 18MB figure you obtained.

$ xcrun bitcode_strip -r Realm.armv7k -o Realm.nobitcode
$ xcrun bitcode_strip -r RealmSwift.armv7k -o RealmSwift.nobitcode
$ size Realm.nobitcode 
5.4M  Realm.nobitcode
$ size RealmSwift.nobitcode
1.2M  RealmSwift.nobitcode

Where 23 + 2.8 - 5.4 - 1.2 == 19.2. I really don't understand how the 18MB is being measured.

I had been sneaking in just under the 50MB limit with Xcode 8 (I would get a warning on submission but it would pass) but after switching to Xcode 9 and updating the project to Swift 3.2 (no other changes) I can no longer submit my app (58MB). Is my only option to rewrite my watchOS app to work without Realm?

From Apple (Sep 19, 2017):

Well, the problem is not yet solved but we understand it better now. The actual size of the Swift code and Swift runtime libraries are not the problem. As I mentioned earlier, the Swift libraries in AppStore submissions include embedded bitcode that takes up a lot of space. That bitcode is not included in the final app -- it is only in the submissions to the AppStore. The problem is that the check for the 50 MB limit is calculating the size based on the content in a submission instead of the final app size, so that Swift apps for watchOS are severely constrained in size. I expect this to be fixed soon but I can't give a specific timeline.

https://forums.developer.apple.com/message/261450#261450

I'm very happy to hear that Apple is finally making progress on that issue!

Was this page helpful?
0 / 5 - 0 ratings