BranchMetrics / sdk-release

TUNE iOS, Android, and Windows native SDKs
https://developers.tune.com/sdk/quick-starts/
GNU General Public License v3.0
55 stars 46 forks source link

Why is the Tune SDK for iOS around 40mb? #26

Closed MarkPerkins closed 7 years ago

MarkPerkins commented 7 years ago

I am looking at the source and i can't figure out why this is the case? We need to minimize the size of this Framework in our project. Is there any advice you can give?

hasjohnb commented 7 years ago

The size of the Framework folder on your Mac is not the same as the size of the SDK in an app. Xcode is pretty smart about how it bundles and distributes binary libraries; it only includes the functions that are actually called. The last time I checked, with the minimum recommended implementation, the Tune SDK for iOS only added about 180 kB to the size of an application bundle, including all the other framework dependencies. Are you seeing something different than that?

MarkPerkins commented 7 years ago

Our issue is that we haven't enabled bitcode yet for our application because of some other dependencies that we use that haven't enabled that. I assuming the size of the framework itself (Tune.framework) is large because its building pre-compiled headers for all of the Valid Architectures (arm64 armv7 armv7s x86_64 i386). I guess until we can enable bitcode in our project we can't take advantage of just compiling just for the architecture required per device. I'm currently verifying the size difference you mentioned, and i'll get back to you on that.

MarkPerkins commented 7 years ago

I can verify that the framework in 40mb.. for each architecture it comes down to around 10mb.

lipo -detailed_info Dependencies/Tune/Tune.framework/Tune Fat header in: Dependencies/Tune/Tune.framework/Tune fat_magic 0xcafebabe nfat_arch 4 architecture i386 cputype CPU_TYPE_I386 cpusubtype CPU_SUBTYPE_I386_ALL offset 88 size 9486544 align 2^2 (4) architecture armv7 cputype CPU_TYPE_ARM cpusubtype CPU_SUBTYPE_ARM_V7 offset 9486632 size 9503496 align 2^2 (4) architecture x86_64 cputype CPU_TYPE_X86_64 cpusubtype CPU_SUBTYPE_X86_64_ALL offset 18990128 size 9712056 align 2^3 (8) architecture arm64 cputype CPU_TYPE_ARM64 cpusubtype CPU_SUBTYPE_ARM64_ALL offset 28702184 size 10461992 align 2^3 (8)

MarkPerkins commented 7 years ago

So here is what i've done.. for the universal Tune target i changed these build options Generate Debug Symbols: NO Precompile Prefix Header: NO Link With Standard Libraries: NO that shrunk it to about half the size..

working on enabling bitcode now or embedding the framework a different way.

hasjohnb commented 7 years ago

With the disclaimer that I haven't tried this in a couple of years (Xcode/iOS versions), I think the size of the library on disk is not correlated to the size that the SDK contributes to the application binary.

I'd recommend building an application without the SDK (possibly a new, empty app), then exporting it as an .ipa file and measuring the size of the archive. Then add the Tune SDK and dependencies to the app and look at how big the archive is. Note that if you don't call any functions from the Tune SDK, the archive size won't change (you can verify this), so you also have to add at least the initialization stuff to your app's code. This is how I arrived at the 180 kB number.

ghost commented 7 years ago

Hi Mark, John is right that the size of the framework you copy into xcode doesn't all get added to the size of your app download because the compiled code is both thinned per architecture and compressed. The Tune framework is all code, so it compresses very well. There are more details on https://developer.apple.com/library/content/qa/qa1795/_index.html including the recommended way to measure your app download size.

I recommend following John's advice and examining an ad-hoc release archive of your app for seeing Tune's impact. There are instructions in the link above.

You can examine the compressed size of each item in the .ipa by opening Terminal and executing the following command:

unzip -lv /path/to/your/thinned_app.ipa

The size column has the compressed size of each file within your .ipa file. You should evaluate this size as you work to reduce the size of resources in your app. You may reduce the size of a resource by a lot, but after producing an .ipa file, you may discover the compressed size of that resource has not changed as dramatically. The most effective technique for reducing the size of an .ipa file is to remove unnecessary resources.

Of course, I'm not suggesting that you remove the Tune, framework :) rather, that the compressed size of the added Tune code will be significantly less than the size of the original framework package we provide.

MarkPerkins commented 7 years ago

Yup, I did my build and the results were correct..

Size.. 193,642,968 - With Tune 192,104,987 - Without Tune 1,537,981 difference, which is about 1/4 what i expected it to be.

Thanks for your help everyone.