>
> [Goes on to show how Hello World is just 1 MB, which is smaller than Go's Hello World]
>
> [Goes on to show how Hello World is just 1 MB, which is smaller than Go's Hello World]
`go build -o /tmp/hello -ldflags='-s -w' /tmp/hello.go && upx --brute /tmp/hello`.
Also worth noting that the author is incorrect about the Avian example being self-contained--it dynamically links against 4 libraries (on OS X, anyway) while the Go version links against zero.
Further, the Avian example is broken on OS X (the GUI loads, but immediately freezes).
Of course, the applications aren't doing the same work, so comparing the binary sizes is silly. I just wanted to point out that avian's tricks are readily accessible for Go programs as well.
And how exactly does that work out on platforms that don't have stable syscalls?
On Windows, Go dynamically links to kernel32.dll and friends.
const io = @import("std").io;
pub fn main() -> %void {
%%io.stdout.printf("Hello, world!\n");
}
It could be a lot smaller, but I'll have to fix an LLVM bug[2] or two.For comparison (these are all with full optimization and stripped):
* Go: 1,006 KB, static executable
* Rust: 411 KB, links to libdl.so, libpthread.so, libgcc.so, libc.so
* C: 6 KB, links to libc.so
* C++: 6 KB, links to libstdc++.so, libc.so
* Nim: 26 KB, links to libdl.so, libc.so
* D: 546 KB, links to libpthread.so, libm.so, librt.so, libdl.so, libgcc.so, libc.so
libc.so is 1.9MB. libstdc++.so is 1.5MB.
[1]: http://ziglang.org/
To show this to the extreme, here's a "hello world" that's less than 30 bytes:
#!/bin/sh
echo Hello world> It’s not a trivial Hello World app at all, yet it’s a standalone self-contained binary that clocks in at only one megabyte. In contrast, “Hello World” in Go generates a binary that is 1.1mb in size, despite doing much less.
If BC concerns weren't a thing, a fresh Java stdlib would remove a ton of the size complaints.