Decodable icon indicating copy to clipboard operation
Decodable copied to clipboard

.framework binary size

Open vytis opened this issue 8 years ago • 5 comments

I was looking through Frameworks folder in our app bundle and noticed that Decodable is one of the largest binaries. We use CocoaPods and data here is from an AdHoc build. Just to list a few other Swift-only frameworks:

Build framework Size
Alamofire.framework 2,5M
Decodable.framework 1,9M
Moya.framework 732K
JSONCodable.framework 612K

I am not too familiar with Swift build process to guess the reasons, but being 3x the size of another JSON mapping lib is a bit surprising.

vytis avatar Sep 16 '16 07:09 vytis

I've thought about this before, but not been too sure of what size would be acceptable. Decodable does code generation for a lot of nested generic types, which is very likely the reason.

The depth is currently set to 4. Reducing it to 2 shrinks the binary size from 1.7 MB to 0.4 MB for me.

I'm not good at CocoaPods but I think it would be possible to add a build setting for this or something. Will look into it.

In the long term, code generation won't likely be needed when Swift supports conditional protocol conformance.

Anviking avatar Sep 16 '16 08:09 Anviking

Not sure if it's possible to have code generated on the fly with CocoaPods. The only thing that comes to mind is maybe have overloads for depth 2 in the main repo and move the rest to a subspec. On the other hand that might be a bad idea if people use them a lot.

vytis avatar Sep 16 '16 12:09 vytis

@vytis given that those are debug builds it doesn't make much sense to compare sizes, since they includes debug information as well as multiple architectures (those are fat binaries). I'd recommend looking at the actual size from an App Store downloaded IPA.

NachoSoto avatar Sep 16 '16 15:09 NachoSoto

@NachoSoto the app in question is not yet public, we are only doing external testing with TestFlight. However I am not aware of an easy way to download .ipa from App Store or TestFlight. Pre iOS9 you could extract the .ipa from device with certain tools, but they don't work anymore.

What would be the best way to compare resulting binary sizes for several frameworks?

vytis avatar Sep 20 '16 13:09 vytis

@vytis if you use Fastlane, you'll most likely find the .ipa in your source directory.

codeOfRobin avatar Nov 13 '16 19:11 codeOfRobin