Swift Binary Size vs. Obj-C

Hi all,

I've seen a ton of blog posts written about all of the cool and exciting
things about Swift, but I haven't see anything really about the downsides
(besides the occasional post about pain points with interoperability).
What's of biggest concern to me when considering migrating my company's app
from Objective-C to Swift is binary size. Swift binary size seems to be
several times larger than Objective-C, and I'm curious what data there is
in the community to support this suspicion.

For some quick data points, I created a single view controller project in
Obj-C and one in Swift, turned off bitcode to get a better idea of what the
binary size on device would be, and archived them. I did this in Xcode 8
Beta 1 using Swift 3 so that I'd make sure to get any binary size
improvements in Swift 3.

The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I know
that the Swift runtime libs are about 4.5 MB, but subtracting that, the
Swift IPA file is still *30x bigger than the Obj-C equivalent*. Next, I
tried adding a simple table view controller, a Person model with a first
and last name, and a data source that puts the first and last names in the
table view in an attempt to make a functioning app. However, the binary
sizes were about the same (the Obj-C one actually decreased to 635 KB).

When we're talking about binary sizes this small, it's not a big deal, but
my company's app is currently 81 MB, about 35 MB of which is code, and the
rest is assets. If the code part of the binary size increases by orders of
magnitude like this, we'll go way over the 100 MB cellular limit that Apple
has set. This is also a really bad experience for customers in emerging
markets like China and India that have poor connections.

Can anyone confirm or deny that Swift binary size is orders of magnitude
larger than Objective-C? I'm looking for the specific increase we'll see to
take to my management in order to make a justification for whether it's
worth it for our customers.

Thanks!

Seth Friedman

1 Like

Swift binaries are so massive currently because there's no ABI stability,
therefore the runtime and support libraries must be packaged with every
application. This should change in the future.

Best,
Austin

···

On Wed, Jun 15, 2016 at 3:43 PM, Seth Friedman via swift-users < swift-users@swift.org> wrote:

Hi all,

I've seen a ton of blog posts written about all of the cool and exciting
things about Swift, but I haven't see anything really about the downsides
(besides the occasional post about pain points with interoperability).
What's of biggest concern to me when considering migrating my company's app
from Objective-C to Swift is binary size. Swift binary size seems to be
several times larger than Objective-C, and I'm curious what data there is
in the community to support this suspicion.

For some quick data points, I created a single view controller project in
Obj-C and one in Swift, turned off bitcode to get a better idea of what the
binary size on device would be, and archived them. I did this in Xcode 8
Beta 1 using Swift 3 so that I'd make sure to get any binary size
improvements in Swift 3.

The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I know
that the Swift runtime libs are about 4.5 MB, but subtracting that, the
Swift IPA file is still *30x bigger than the Obj-C equivalent*. Next, I
tried adding a simple table view controller, a Person model with a first
and last name, and a data source that puts the first and last names in the
table view in an attempt to make a functioning app. However, the binary
sizes were about the same (the Obj-C one actually decreased to 635 KB).

When we're talking about binary sizes this small, it's not a big deal, but
my company's app is currently 81 MB, about 35 MB of which is code, and the
rest is assets. If the code part of the binary size increases by orders of
magnitude like this, we'll go way over the 100 MB cellular limit that Apple
has set. This is also a really bad experience for customers in emerging
markets like China and India that have poor connections.

Can anyone confirm or deny that Swift binary size is orders of magnitude
larger than Objective-C? I'm looking for the specific increase we'll see to
take to my management in order to make a justification for whether it's
worth it for our customers.

Thanks!

Seth Friedman

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Yep, I just took a simple app and opened up the ipa. 90% of it is the
“Frameworks” directory containing the Swift frameworks libSwiftCore.dylib,
libSwiftDarwin.dylib, etc.

···

On Wed, Jun 15, 2016 at 3:43 PM Seth Friedman via swift-users < swift-users@swift.org> wrote:

Hi all,

I've seen a ton of blog posts written about all of the cool and exciting
things about Swift, but I haven't see anything really about the downsides
(besides the occasional post about pain points with interoperability).
What's of biggest concern to me when considering migrating my company's app
from Objective-C to Swift is binary size. Swift binary size seems to be
several times larger than Objective-C, and I'm curious what data there is
in the community to support this suspicion.

For some quick data points, I created a single view controller project in
Obj-C and one in Swift, turned off bitcode to get a better idea of what the
binary size on device would be, and archived them. I did this in Xcode 8
Beta 1 using Swift 3 so that I'd make sure to get any binary size
improvements in Swift 3.

The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I know
that the Swift runtime libs are about 4.5 MB, but subtracting that, the
Swift IPA file is still *30x bigger than the Obj-C equivalent*. Next, I
tried adding a simple table view controller, a Person model with a first
and last name, and a data source that puts the first and last names in the
table view in an attempt to make a functioning app. However, the binary
sizes were about the same (the Obj-C one actually decreased to 635 KB).

When we're talking about binary sizes this small, it's not a big deal, but
my company's app is currently 81 MB, about 35 MB of which is code, and the
rest is assets. If the code part of the binary size increases by orders of
magnitude like this, we'll go way over the 100 MB cellular limit that Apple
has set. This is also a really bad experience for customers in emerging
markets like China and India that have poor connections.

Can anyone confirm or deny that Swift binary size is orders of magnitude
larger than Objective-C? I'm looking for the specific increase we'll see to
take to my management in order to make a justification for whether it's
worth it for our customers.

Thanks!

Seth Friedman

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
-Saagar Jha

Does anyone have an estimate of how far off this future is? Presumably it involves the runtime libraries being bundled into the OS … so would this happen in iOS 10 / macOS 10.12?

I’d love to use Swift, but I work on a framework <https://github.com/couchbase/couchbase-lite-ios/&gt; for use by other apps, and I can’t justify adding any Swift code to the framework if that would suddenly cause everyone’s app size to balloon by ~5MB. (Except for devs already using Swift in their apps, true, but I don’t know how many of them are.)

—Jens

···

On Jun 15, 2016, at 5:02 PM, Austin Zheng via swift-users <swift-users@swift.org> wrote:

Swift binaries are so massive currently because there's no ABI stability, therefore the runtime and support libraries must be packaged with every application. This should change in the future.

Thanks for the quick reply. You guys are right on part of it; the runtime
libraries are causing the majority of the increase. I thought the Swift
runtime libraries were supposed to only take up 4.5 MB though? Did they
increase with Swift 3? If I add up all of the libraries, they take up a
total of 22.88 MB in the binary. About how big would they be if I had
Bitcode turned on?

That said, the actual Swift binary is still larger. In my table view
example, the Objective-C binary is 144 KB and the Swift binary is 201
KB. *That's
still a 40% increase*. Obviously it's much harder to test a large-scale
app, but I'd like to know the percentage increase to expect if we were to
migrate to Swift.

···

On Wed, Jun 15, 2016 at 5:04 PM Saagar Jha <saagarjha28@gmail.com> wrote:

Yep, I just took a simple app and opened up the ipa. 90% of it is the
“Frameworks” directory containing the Swift frameworks libSwiftCore.dylib,
libSwiftDarwin.dylib, etc.

On Wed, Jun 15, 2016 at 3:43 PM Seth Friedman via swift-users < > swift-users@swift.org> wrote:

Hi all,

I've seen a ton of blog posts written about all of the cool and exciting
things about Swift, but I haven't see anything really about the downsides
(besides the occasional post about pain points with interoperability).
What's of biggest concern to me when considering migrating my company's app
from Objective-C to Swift is binary size. Swift binary size seems to be
several times larger than Objective-C, and I'm curious what data there is
in the community to support this suspicion.

For some quick data points, I created a single view controller project in
Obj-C and one in Swift, turned off bitcode to get a better idea of what the
binary size on device would be, and archived them. I did this in Xcode 8
Beta 1 using Swift 3 so that I'd make sure to get any binary size
improvements in Swift 3.

The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I know
that the Swift runtime libs are about 4.5 MB, but subtracting that, the
Swift IPA file is still *30x bigger than the Obj-C equivalent*. Next, I
tried adding a simple table view controller, a Person model with a first
and last name, and a data source that puts the first and last names in the
table view in an attempt to make a functioning app. However, the binary
sizes were about the same (the Obj-C one actually decreased to 635 KB).

When we're talking about binary sizes this small, it's not a big deal,
but my company's app is currently 81 MB, about 35 MB of which is code, and
the rest is assets. If the code part of the binary size increases by orders
of magnitude like this, we'll go way over the 100 MB cellular limit that
Apple has set. This is also a really bad experience for customers in
emerging markets like China and India that have poor connections.

Can anyone confirm or deny that Swift binary size is orders of magnitude
larger than Objective-C? I'm looking for the specific increase we'll see to
take to my management in order to make a justification for whether it's
worth it for our customers.

Thanks!

Seth Friedman

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
-Saagar Jha

Sorry, I totally missed the part where you mentioned the runtime libs.

I assume you're compiling your Objective-C code using the `-Os`
optimization level? Unfortunately, it doesn't seem like swiftc has any
flags for trading off speed and binary size. Part of the size discrepancy
is almost certainly due to the immaturity of the compiler.

This is probably only valid for the roughest of OOM estimates, but
LinkedIn's iOS app is 135 MB (don't know how it breaks down in terms of
assets vs code), and is almost entirely implemented in Swift. It's not much
to go off, but it might provide you with a starting point.

If any of your company's engineers are at WWDC, you might want to have them
ask the engineers during the developer tools labs.

Best,
Austin

···

On Wed, Jun 15, 2016 at 5:16 PM, Seth Friedman via swift-users < swift-users@swift.org> wrote:

Thanks for the quick reply. You guys are right on part of it; the runtime
libraries are causing the majority of the increase. I thought the Swift
runtime libraries were supposed to only take up 4.5 MB though? Did they
increase with Swift 3? If I add up all of the libraries, they take up a
total of 22.88 MB in the binary. About how big would they be if I had
Bitcode turned on?

That said, the actual Swift binary is still larger. In my table view
example, the Objective-C binary is 144 KB and the Swift binary is 201 KB. *That's
still a 40% increase*. Obviously it's much harder to test a large-scale
app, but I'd like to know the percentage increase to expect if we were to
migrate to Swift.

On Wed, Jun 15, 2016 at 5:04 PM Saagar Jha <saagarjha28@gmail.com> wrote:

Yep, I just took a simple app and opened up the ipa. 90% of it is the
“Frameworks” directory containing the Swift frameworks libSwiftCore.dylib,
libSwiftDarwin.dylib, etc.

On Wed, Jun 15, 2016 at 3:43 PM Seth Friedman via swift-users < >> swift-users@swift.org> wrote:

Hi all,

I've seen a ton of blog posts written about all of the cool and exciting
things about Swift, but I haven't see anything really about the downsides
(besides the occasional post about pain points with interoperability).
What's of biggest concern to me when considering migrating my company's app
from Objective-C to Swift is binary size. Swift binary size seems to be
several times larger than Objective-C, and I'm curious what data there is
in the community to support this suspicion.

For some quick data points, I created a single view controller project
in Obj-C and one in Swift, turned off bitcode to get a better idea of what
the binary size on device would be, and archived them. I did this in Xcode
8 Beta 1 using Swift 3 so that I'd make sure to get any binary size
improvements in Swift 3.

The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I know
that the Swift runtime libs are about 4.5 MB, but subtracting that, the
Swift IPA file is still *30x bigger than the Obj-C equivalent*. Next, I
tried adding a simple table view controller, a Person model with a first
and last name, and a data source that puts the first and last names in the
table view in an attempt to make a functioning app. However, the binary
sizes were about the same (the Obj-C one actually decreased to 635 KB).

When we're talking about binary sizes this small, it's not a big deal,
but my company's app is currently 81 MB, about 35 MB of which is code, and
the rest is assets. If the code part of the binary size increases by orders
of magnitude like this, we'll go way over the 100 MB cellular limit that
Apple has set. This is also a really bad experience for customers in
emerging markets like China and India that have poor connections.

Can anyone confirm or deny that Swift binary size is orders of magnitude
larger than Objective-C? I'm looking for the specific increase we'll see to
take to my management in order to make a justification for whether it's
worth it for our customers.

Thanks!

Seth Friedman

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
-Saagar Jha

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Does anyone know if the runtime libs definitively increased in size in
Swift 3? I could have sworn I heard 4.5 MB for Swift 2.

Also, does anyone know if there are plans to introduce a `-Os` equivalent
for Swift? (Yes, I'm using that in Obj-C, to answer your question).

Thanks!

Seth

···

On Wed, Jun 15, 2016 at 5:27 PM Austin Zheng <austinzheng@gmail.com> wrote:

Sorry, I totally missed the part where you mentioned the runtime libs.

I assume you're compiling your Objective-C code using the `-Os`
optimization level? Unfortunately, it doesn't seem like swiftc has any
flags for trading off speed and binary size. Part of the size discrepancy
is almost certainly due to the immaturity of the compiler.

This is probably only valid for the roughest of OOM estimates, but
LinkedIn's iOS app is 135 MB (don't know how it breaks down in terms of
assets vs code), and is almost entirely implemented in Swift. It's not much
to go off, but it might provide you with a starting point.

If any of your company's engineers are at WWDC, you might want to have
them ask the engineers during the developer tools labs.

Best,
Austin

On Wed, Jun 15, 2016 at 5:16 PM, Seth Friedman via swift-users < > swift-users@swift.org> wrote:

Thanks for the quick reply. You guys are right on part of it; the runtime
libraries are causing the majority of the increase. I thought the Swift
runtime libraries were supposed to only take up 4.5 MB though? Did they
increase with Swift 3? If I add up all of the libraries, they take up a
total of 22.88 MB in the binary. About how big would they be if I had
Bitcode turned on?

That said, the actual Swift binary is still larger. In my table view
example, the Objective-C binary is 144 KB and the Swift binary is 201 KB. *That's
still a 40% increase*. Obviously it's much harder to test a large-scale
app, but I'd like to know the percentage increase to expect if we were to
migrate to Swift.

On Wed, Jun 15, 2016 at 5:04 PM Saagar Jha <saagarjha28@gmail.com> wrote:

Yep, I just took a simple app and opened up the ipa. 90% of it is the
“Frameworks” directory containing the Swift frameworks
libSwiftCore.dylib, libSwiftDarwin.dylib, etc.

On Wed, Jun 15, 2016 at 3:43 PM Seth Friedman via swift-users < >>> swift-users@swift.org> wrote:

Hi all,

I've seen a ton of blog posts written about all of the cool and
exciting things about Swift, but I haven't see anything really about the
downsides (besides the occasional post about pain points with
interoperability). What's of biggest concern to me when considering
migrating my company's app from Objective-C to Swift is binary size. Swift
binary size seems to be several times larger than Objective-C, and I'm
curious what data there is in the community to support this suspicion.

For some quick data points, I created a single view controller project
in Obj-C and one in Swift, turned off bitcode to get a better idea of what
the binary size on device would be, and archived them. I did this in Xcode
8 Beta 1 using Swift 3 so that I'd make sure to get any binary size
improvements in Swift 3.

The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I
know that the Swift runtime libs are about 4.5 MB, but subtracting that,
the Swift IPA file is still *30x bigger than the Obj-C equivalent*.
Next, I tried adding a simple table view controller, a Person model with a
first and last name, and a data source that puts the first and last names
in the table view in an attempt to make a functioning app. However, the
binary sizes were about the same (the Obj-C one actually decreased to 635
KB).

When we're talking about binary sizes this small, it's not a big deal,
but my company's app is currently 81 MB, about 35 MB of which is code, and
the rest is assets. If the code part of the binary size increases by orders
of magnitude like this, we'll go way over the 100 MB cellular limit that
Apple has set. This is also a really bad experience for customers in
emerging markets like China and India that have poor connections.

Can anyone confirm or deny that Swift binary size is orders of
magnitude larger than Objective-C? I'm looking for the specific increase
we'll see to take to my management in order to make a justification for
whether it's worth it for our customers.

Thanks!

Seth Friedman

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--
-Saagar Jha

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

The total of the Frameworks dir in a Swift 2.2 app I have is 5.8M. The breakdown for this app is:

64K libswiftAppKit.dylib
4.8M libswiftCore.dylib
44K libswiftCoreData.dylib
112K libswiftCoreGraphics.dylib
32K libswiftCoreImage.dylib
84K libswiftDarwin.dylib
40K libswiftDispatch.dylib
516K libswiftFoundation.dylib
64K libswiftObjectiveC.dylib
48K libswiftWebKit.dylib

So how big might partially depend upon what frameworks the app uses. The same app in Swift 3 is 6.6M -- a little bit bigger. It’s breakdown is:

76K libswiftAppKit.dylib
4.5M libswiftCore.dylib
44K libswiftCoreData.dylib
116K libswiftCoreGraphics.dylib
36K libswiftCoreImage.dylib
68K libswiftDarwin.dylib
40K libswiftDispatch.dylib
552K libswiftFoundation.dylib
36K libswiftIOKit.dylib
64K libswiftObjectiveC.dylib
1.0M libswiftSwiftOnoneSupport.dylib
48K libswiftWebKit.dylib
36K libswiftXPC.dylib

The Swift 3 version is a debug build, the swift 2.2 version isn’t.

···

On Jun 15, 2016, at 5:37 PM, Seth Friedman via swift-users <swift-users@swift.org> wrote:

Does anyone know if the runtime libs definitively increased in size in Swift 3? I could have sworn I heard 4.5 MB for Swift 2.

I'm seeing 7.375 MB for Swift 3 dylibs with a Release build, and I don't
have WebKit, XPC, OnoneSupport, IOKit, CoreData, and AppKit in my binary
when I create just a bare bones app.

Thanks,
Seth

···

On Wed, Jun 15, 2016 at 5:59 PM Marco S Hyman <marc@snafu.org> wrote:

On Jun 15, 2016, at 5:37 PM, Seth Friedman via swift-users < > swift-users@swift.org> wrote:
>
> Does anyone know if the runtime libs definitively increased in size in
Swift 3? I could have sworn I heard 4.5 MB for Swift 2.

The total of the Frameworks dir in a Swift 2.2 app I have is 5.8M. The
breakdown for this app is:

64K libswiftAppKit.dylib
4.8M libswiftCore.dylib
44K libswiftCoreData.dylib
112K libswiftCoreGraphics.dylib
32K libswiftCoreImage.dylib
84K libswiftDarwin.dylib
40K libswiftDispatch.dylib
516K libswiftFoundation.dylib
64K libswiftObjectiveC.dylib
48K libswiftWebKit.dylib

So how big might partially depend upon what frameworks the app uses. The
same app in Swift 3 is 6.6M -- a little bit bigger. It’s breakdown is:

76K libswiftAppKit.dylib
4.5M libswiftCore.dylib
44K libswiftCoreData.dylib
116K libswiftCoreGraphics.dylib
36K libswiftCoreImage.dylib
68K libswiftDarwin.dylib
40K libswiftDispatch.dylib
552K libswiftFoundation.dylib
36K libswiftIOKit.dylib
64K libswiftObjectiveC.dylib
1.0M libswiftSwiftOnoneSupport.dylib
48K libswiftWebKit.dylib
36K libswiftXPC.dylib

The Swift 3 version is a debug build, the swift 2.2 version isn’t.