Russ Cox commented on a couple of the proposed fixes:<p>> Maybe after the compiler is converted to Go.<p>> I'm not willing to make major changes to escape analysis right now. I intend to ask someone to take a look at the whole thing and see whether it should be changed/rewritten/fixed/etc in a few weeks.<p>It sounds to me like there are some significant changes coming down the pipe anyway, which may or may not effect the current escape analysis behavior.
[tl;dr: I suspect the Go GC isn't very good]<p>I'm interested and surprised to see people putting much effort into escape analysis for stack allocation. The research that came out in the 90s and 00s pretty much said that if you have a good GC you won't see much benefit to using EA for stack allocation.<p>[Disclaimer: All of the below written with the expectation of being wrong because my knowledge is out of date, my memory is bad, and/or there are specifics to Go or the implementation which invalidates my points. Still wrote it cause it might be interesting to others or lead to interesting conversation]<p>OK, why do I say that. Well:<p>- It's very expensive to do EA well (O(n^3) or O(n^6) where n is the depth of the call graph). You can do it cheaper in a JIT that has on-stack-replacement (basically where you make optimistic assumptions and reoptimize if your assumptions are invalidated)<p>- You do get good payoff from stack allocation, in terms of time spent allocating and deallocating memory.<p>- The real payoff from EA is to allow synchronization removal in Java (which shouldnt matter for Go).<p>- Stack allocation provides cheap allocation (don't need a malloc, you can just do an alloca, which is a cheap add operation), but a good copying GC provides bump allocation which is better.<p>- Stack allocation provides cheap deallocation, but not as cheap as a generational GC which can clear the young generation for very very cheap.<p>- Stack allocation also extends object lifetimes, which is bad.<p>- Stack allocation also allows you to move object fields into variables which can get values out of memory and into registers, which is good.<p>- Stack allocation also has worse locality than a good GC (a copying collector has amazing locality, putting things on the stack doesn't necessarily).<p>So all this, plus the details in the doc, imply that the Go GC isn't very good. If it were good, it would have better allocation performance than you would get from stack allocation, and the only thing left would be that the benefit from moving values into fields outweighs the costs.<p>I don't know anything about Go, so this may not be possible, but as a total bystander with no info at all, I'd say don't work on optimizing EA and instead focus on improving the GC.<p>[disclaimer: please reread disclaimer above]
The author, Dmitry, had a recent escape analysis fix related to maps with impressive results:<p><a href="https://go.googlesource.com/go/+/b3be360f16c44d21b2594d06e8d0e609e8fe3c0c" rel="nofollow">https://go.googlesource.com/go/+/b3be360f16c44d21b2594d06e8d...</a>
Fixing the "dot-dot-dot arguments always escape" issue could in particular mean that logging code no longer risks making things escape even when it doesn't run:<p><a href="http://stackoverflow.com/questions/27788813/variadic-functions-causing-unnecessary-heap-allocations-in-go" rel="nofollow">http://stackoverflow.com/questions/27788813/variadic-functio...</a><p>...which would be cool.