5 comments

[ 2.6 ms ] story [ 22.7 ms ] thread
Does Go do any LTO? It's good that they throw away unexported unused routines from my code, but it'd be better if they also didn't link in unused routines from the standard library (assuming no reflection is being used).
I thought that's exactly what this article describes: "Similarly the linker can discard other exported methods, those that are only accessible through reflection, if the corresponding reflection features are not used anywhere in the program. That change shrinks binaries by 5–20%."
Could be. I read that as discarding user-defined methods, not library-provided methods. Hopefully it is both.
The technique described in the blog post doesn't differentiate between user code and library code. It's all code. Any method the linker or the compiler can get rid of it does.
Hi all. Something I left out of the post that I should have mentioned: if you are wondering why a Hello World program is hundreds of kilobytes instead of tens like a C program, it is because Go programs are statically linked.

You can dynamically link Go on linux to see similar numbers:

    $ go install -buildmode=shared std
    $ go build -linkshared hello.go 
    $ ./hello 
    Hello, World!
    $ ls -l hello
    -rwxr-x--- 1 crawshaw eng 15713 Aug 18 19:26 hello
(Dynamic linking in Go was funded by Canonical, which is pretty cool!)