by arsv · 11y ago · 0 comments
Still producing 1.3M hello world executables.
I wonder if rewriting the linker from C to Go will be primarily rewriting, or maybe they will start fixing it somehow.
The linkers in the gc tool chain (5l, 6l, and 8l) do static linking. All Go binaries therefore include the Go run-time, along with the run-time type information necessary to support dynamic type checks, reflection, and even panic-time stack traces.
A simple C "hello, world" program compiled and linked statically using gcc on Linux is around 750 kB, including an implementation of printf. An equivalent Go program using fmt.Printf is around 1.9 MB, but that includes more powerful run-time support and type information.
diet gcc -o hello hello.c; strip hello
2280 bytes on my system.
There are reasons why using glibc results in executables so big, and why it is tolerated (kind of). Those reasons hardly apply to a new language being actively developed. Yet said language produces executables almost twice the size.
"Run-time support and type information", why is it linked into a an executable that never allocates memory and does no introspection of any kind?
fmt.Print does use reflection.
Besides, bickering over the size of hello world is pretty pointless; better to compare the size of programs that actually do something.
We do recognise that Go binaries can and should be smaller, but probably not as small as you might hope.
It is not about the size of hello world executable, that is just a symptom. A code smell if you like. There is something badly broken in the dead code (or dead data) elimination area. And I hope that code is in fact dead, because if it is not, add code generation to the list of smelly things.
What I suspect I see here is a kind of C++ vtable problem built deep into the language design somewhere. And the reaction is, let's talk about large executables so that it would kinda become not so visible. Or maybe let's take a look at glibc, because glibc is definitely a paragon of clear design befitting a new language.
> fmt.Print does use reflection
There are two problems with this. The lesser one is why does it need reflection to print a string. The bigger one is why do I see about 600 reflect.* entries in the resulting ELF instead of a single one for the string type.
Statically. Care to check "ldd hello" of your binary?
In case you wonder, that's dietlibc which is typically built with no dynamic linking capabilities whatsover.
1.3 megabytes. That's like $0.00004 USD worth of hard drive space.
Does the go team think we are all rich or something?
The code that actually executes is not bloated. It's not the most efficient code in the world, because the compilers don't have an optimizer as advanced as gcc's, but it's not unreasonably large.
Anyway it can be improved, but to me there are far more important things to be improved about Go than the binary size of small programs.
% du -k eval/eval
2040 eval/eval
% strip eval/eval
% du -k eval/eval
1864 eval/eval
Don't just assume. Measure.It's a tradeoff, and worth it in my opinion.