Learning how to trade stocks books14 comments
Hedge fund execution trader jobs
Ok, I lied, there's no weird trick. However, you can easily reduce a Go binary size by more than 6 times with some flags and common tools. I don't actually believe a 30MB static binary is a problem in this day and age, and I would not trade build time complexity performance debug-ability for it, but people care about it apparently , so here we are.
For the record, the dev team cares about it, too. It all started with an observation Jessie Frazelle made: Not a surprise if you look at the entropy graph generated with binwalk. A lot of sections there should compress extremely well. When I mentioned this is the office John Graham-Cumming suggested that we should then just make binaries self-decompress at runtime.
At first I though he was joking, then I realized that no, this almost made sense! So this weekend was going to be about hard-core engineering, building a binary that decompresses a payload and then JMP s to it. But soon enough I found out that such a thing exists already, it's called UPX and is quite nice. Before we go all in on compression, there's something we can do to make binaries smaller: We can use the -s and -w linker flags to strip the debugging information like this:.
Here's the new entropy graph; you can see that the last pretty-low entropy section is gone. Interestingly, what gets stripped is only the DWARF tables needed for debuggers, not the annotations needed for stack traces, so our panics are still readable! Next step, let's run upx. It works out of the box on linux binaries built by 1. We went from 12MB to 2. Almost 7 times smaller! Here's a graph of the sizes obtained by each technique, applied to the Go compiler, to Gogs and to hello. Obviously decompression is not free, but the overhead should only be at process start.
In my benchmarks the UPX version of go was taking ms more to start, and hello 15ms. Here 's all the data and here is the simple build script I used. If you like reading interesting facts about Go in a totally-not-Buzzfeed style, you might want to follow me on Twitter.