Size of the swift runtime and minimal app

Hi,

What's the size of the swift runtime and also a minimal hello world type of app?

I assume you mean a command-line app, never built a Swift GUI app. It is not hard to check this for yourself, here are the commands I ran on Ubuntu 20.04:

> ./swift-5.3.1-RELEASE-ubuntu20.04/usr/bin/swiftc -O swift/swift/test/Interpreter/hello_toplevel.swift
> ls -l hello_toplevel
-rwxrwxr-x 1 butta butta 15184 Dec 12 03:52 hello_toplevel

Interestingly, the unoptimized version is slightly smaller, there's also the -Osize flag.

> readelf -d hello_toplevel | ag libswift
 0x0000000000000001 (NEEDED)             Shared library: [libswiftCore.so]
> ls -l swift-5.3.1-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftCore.so
-rwxr-xr-x 1 butta butta 7850184 Nov 12 10:51 swift-5.3.1-RELEASE-ubuntu20.04/usr/lib/swift/linux/libswiftCore.so

So the usual answers to your questions are 7,850,184 and 15,184 bytes. Since that's a shared library, it depends on several other non-Swift libraries like libicu, libpthread, and so on.

Alternately, you can statically compile in the stdlib and libicu:

> ./swift-5.3.1-RELEASE-ubuntu20.04/usr/bin/swiftc -O -static-stdlib swift/swift/test/Interpreter/hello_toplevel.swift
> ls -l hello_toplevel
-rwxrwxr-x 1 butta butta 36223720 Dec 12 04:17 hello_toplevel

Most of that is probably libicudata, which is almost 28 MB. Maybe LTO could get rid of other unneeded functions.

If you care about code size (e.g. doing embedded systems development) then I'd recommend building teh stdlib without unicode / ICU support. I'd get in touch with the Swift for Arduino folks about this for example. They're a friendly and great bunch.

3 Likes
Terms of Service

Privacy Policy

Cookie Policy