11 ms·
Life without line numbers for 6% smaller Go binaries
- ottoboney 6y agoYour HTTP cert is invalid. Just a heads up.
- donmcronald 6y agoIt's fine for me and was issued May 26. The URL when I visited was https://commaok.xyz https://commaok.xyz
- rnotaro 6y agoHis browser might have oppened the following link: https://www.commaok.xyz/post/no-line-numbers/ https://www.commaok.xyz/post/no-line-numbers/ somehow. It's serving a certificate for github.com.
- stevekemp 6y agoThere's an error for https://www.commaok.xyz/ https://www.commaok.xyz/, for what that's worth.
- msbarnett 6y agoIf it's showing up as invalid for you, you may have locally revoked trust of the DST Root CA X3 IdenTrust root certificate.
- sli 6y agoThe www subdomain serves the wrong cert. https://www.commaok.xyz/ https://www.commaok.xyz/ gives you an SSL error but https://commaok.xyz/ https://commaok.xyz/ does not.
- drudru11 6y agoHi : unrelated to this thread. In an older thread you mention an acronym TFA. The thread was a discussion on sparse files and removing bytes from the front of a file. What is TFA?
- svnpenn 6y agoThis didnt seem to change anything for me. I am currently using Go 1.14.4 (Windows), and after trying go1.15beta1, the resultant executables are actually larger. Another thing Ive always found strange is people always recommend (-ldflags -w), when (-ldflags -s) gives smaller result, and (-ldflags '-s -w') is identical to (-ldflags -s).
- skykooler 6y agoGiven the article is talking about DWARF debugging formats, I believe the numbers in the article are for Linux binaries. I'm not sure if Windows binaries store line numbers in the same way.
- ygra 6y agoDoesn't Windows usually just use a .pdb file next to the exe/dll, containing the debugging information? So stripping debug information on Windows is just deleting (or not distributing) that file.
- mehrdadn 6y agoNot entirely, there's also a debug directory embedded inside executables that gets stripped.
- kjksf 6y agoYes, .pdb files are used by most toolchains for debug information on Windows. No, Go doesn't use .pdb files. On all platforms Go stores a significant amount of meta-data in the binary, in the same format so that they can access it using the same code on all platforms. This information is used by the runtime. Precise garbage collector needs to know the layout of structures and stack to know which fields are pointers; To generate readable callstack Go needs info about function and where they come from (source code file name, position). etc. A sidenote: you can convert DWARF debug info to .pdb using external tool which allows debugging Go programs with Windows native debuggers like WinDBG.
- varbhat 6y agohttps://blog.filippo.io/shrink-your-go-binaries-with-this-one-weird-trick/ https://blog.filippo.io/shrink-your-go-binaries-with-this-on... This is great article instructing how to shrink the Go Binaries. Author is lead of cryptography and security team of Go Team at Google.
- distortedsignal 6y agoCompletely agree. I performed the steps in the article and reduced the output binary size from ~35 MB for raw go build to around 29 MB for go build with the ldflags all the way down to 8.3 MB for compressed with upx. Really impressive results.
- Karunamon 6y agoDoes UPX still trigger virus scanners, though? As much as I like the idea of tinier binaries, the chance that your user's endpoint security is going to freak out makes it not worth the hassle.
- alternatetwo 6y agoNever mind that, startup times are atrocious with such a huge upx packed binary ...
- distortedsignal 6y agoThat's an interesting point. I hadn't tested the startup times of the upx binary before, so I just did by running `time $binary_name --help`. For my binary, this should print a simple help message and quit. Big: 0.04s user 0.01s system 101% cpu 0.054 total Med: 0.04s user 0.01s system 99% cpu 0.048 total Sm : 0.14s user 0.02s system 99% cpu 0.163 total So you're right - it makes execution time take about 3x as long. However, in my case, 3x slower is a fine trade off to make.
- devonkim 6y agoUPX binaries throw off most endpoint security models and so we have a chicken and egg problem where its more common use is for malware authors than commercial software vendors. But once UPX binary signatures are in significantly wider use new models can be developed to better score legit binaries.
- birdyrooster 6y agoI wonder how much more from javascript minifying can be reused in this space.
- coldtea 6y agoProbably not much? Javascript minifying is about raw source code, whereas those are binary instructions + debug info.
- kardos 6y agoHow much better does a 6% smaller go binary perform?
- jeffbee 6y agoShrinking the line table will be irrelevant to performance. As I understand it, the tailscale binary has a hard size requirement to run as a VPN under iOS.
- jeffbee 6y agoSince the Go compiler is so primitive you can strongly influence the size of the program by just restructuring it. An example: if you have a function that converts integer return codes to errors, and you have another function that calls it a lot: func codeToError(i int) error { switch i { case ... ... } } func stuff() error { if rv := callJunk(); rv < 0 { return codeToError(rv) } if rv := moreJunk(); rv < 0 { return codeToError(rv) } ... return nil } You're going to get multiple whole copies of the inner function inlined into the outer one. This can add up, if the outer function is long and/or if the inner switch statement is huge. You can save a lot of code by jumping through an adapter function instead, like: func callWithErrorsConverted(f func() int, g func(int) error) error { return g(f()) } ... because now the compiler doesn't get to inline g into f. These things make a big difference in whole-program size. I wrote about it in the context of tailscale and protobufs here: https://paper.dropbox.com/doc/Bloaty-Puffs-and-the-Go-Compiler--A4NFFR1SRcfOaz0kMw0ITuQ0AQ-YiblPOe6AD2tKfEj5RzFT https://paper.dropbox.com/doc/Bloaty-Puffs-and-the-Go-Compil...
- pantalaimon 6y agoI’m pretty happy I don’t have to worry about such details in C and can rely on the compiler to do the easy optimizations for me.
- ascar 6y agoWait, isn't that trick basically about avoiding optimization (inlining the function to avoid the context switch) to reduce code size? The C compiler would do something similar here and also increase code size for performance unless you explicitly use `-Os`
- monocasa 6y agoThe better C compilers use better heuristics in these cases, knowing that binary size can mean I$ pressure and therefore be a detriment to performance.
- pansa2 6y ago> You can usually save double-digit percentages by stripping debugging information: pass `-ldflags=-w` to `go build`. Is there a way to make `go build` for a particular project always use `-ldflags=-w`? Or do I have to remember to type it in every time (or hide my `go build` command inside a Makefile or `build.sh`)?