241 points · by dcu · 9y ago · 73 comments
It's not some weird, exotic form of inlining; it's just a more complete version than Go used to have.
I for one am very glad that more work is put into inlining
But instead, you come along and criticize them for being too specific with their terms (!!) and also accuse them of being deceptive. This is not a marketing exercise. There is no conspiracy here.
As far as programming languages go, Go is very new. Of course, there will be a number of areas that still need to be optimized or fully fleshed out. I think the Go compiler has only been written in Go for about a year. I'm sure you you find this pretty lame as well.
Since I've learned about continuation passing style (which Go channels could probably be formally transformed into), I've been convinced that there's a better way to do codegen. Better calling convention, better stack representation, better instruction architecture; I'm not yet sure - it's a nag continuously at the back of my mind, almost as though it's at the tip of my tongue. In this specific case, it must surely be possible to inline a continuation with some foreign architecture. I'd love to see some literature on the more experimental end of this stuff, if anyone has it.
https://www.amazon.com/Compiling-Continuations-Andrew-W-Appe...
More recently though I heard someone proved mathematically that CPS can be transformed one-for-one into one of the more conventional models. That doesn't mean it might not still be easier for the humans to deal with however.
Byproduct of that could be little hacky things like this below that make code faster by restructuring code a little
https://techblug.wordpress.com/2013/08/19/java-jit-compiler-...
You should be able to get about 15-20% with about 3-5% binary increase size.
In fact, with ThinLTO, we often see that gain with binary size decrease from smart inlining choices.
(The heuristics for inlining take a very very long time to get right and tune)
The issue they will next hit is that inlining is going to make the compiler slower until they tune the heuristics well.
1. The compiler is a lot slower, which is usually from code growth and not debugging info growth. If the compiler is that much slower from debugging info growth, they have larger issues :) 2. Usually people do not include debug info sizes in binary sizes, because DWARF/et al info can be stripped and put alongside the binary (IE it doesn't even have to be part of the binary)
https://github.com/golang/go/issues/19386
Those numbers are just for my CLs that fix stack traces but with mid-stack inlining still off. Turning it on makes builds noticeably slower:
$ time ./make.bash
real: 45.32s user: 118.67s cpu: 5.85s
$ time GO_GCFLAGS='-l=4' ./make.bash
real: 64.51s user: 167.04s cpu: 7.12s
We'll need to tweak the inlining heuristic to find a good balance between performance, build times, and binary size.dl.google.com has been golang since 2013. Imagine the traffic that application gets!
That said, it's a little disappointing when runtimes require custom algorithms or metadata to walk the stack and construct a stack trace. It makes it harder to build debuggers that grok the state of multiple runtimes (e.g., the Go code and the C code in the same program). This also affects runtime tracing tools like DTrace, which by construction can't rely on runtime support for help.
That doesn't make sense to me. The complicated part is storing the IR in packages in a form that can be read back into the compiler later. That's needed to do inlining at all. Once you have that done, doing LTO is trivial: you just slurp your IR for all modules linked together into the compiler and emit a single binary. (You can be fancier, like ThinLTO does, but again, the effort needed to do ThinLTO is independent of whether you have cyclic dependencies or not.)
So it records the calling convention, architecture flags, alignment, and other ABI pieces etc? As well as an estimate of instruction-level inlining cost, summary info about arguments, etc, so you effectively decide whether inlining it will help or hurt, without having the IR around to try?
FWIW: Writing out the info is usually not the hard part, actually, and is unrelated to the DAG-ness of the packages.
GCC is just the perennial example here, but they refused to write it out for years for political reasons, not technical ones :)
No. At the moment it records the AST in the object file, because the inliner works at the Go AST level. In the future it may instead record the SSA representation (which would obviously give better cost estimates; the current heuristics are really extremely simple).
"FWIW: Writing out the info is usually not the hard part, actually, and is unrelated to the DAG-ness of the packages."
The DAG-ness means it's always available when compiling the call site, even if it's a cross-package call. It means you don't have to do it at link time.