TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Go Escape Analysis Flaws

82 pointsby diakritikalover 10 years ago

5 comments

xdissentover 10 years ago
Russ Cox commented on a couple of the proposed fixes:<p>&gt; Maybe after the compiler is converted to Go.<p>&gt; I&#x27;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&#x2F;rewritten&#x2F;fixed&#x2F;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.
评论 #9042241 未加载
pbiggarover 10 years ago
[tl;dr: I suspect the Go GC isn&#x27;t very good]<p>I&#x27;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&#x27;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&#x2F;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&#x27;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&#x27;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&#x27;t necessarily).<p>So all this, plus the details in the doc, imply that the Go GC isn&#x27;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&#x27;t know anything about Go, so this may not be possible, but as a total bystander with no info at all, I&#x27;d say don&#x27;t work on optimizing EA and instead focus on improving the GC.<p>[disclaimer: please reread disclaimer above]
评论 #9041442 未加载
评论 #9042306 未加载
评论 #9041448 未加载
评论 #9042052 未加载
评论 #9043485 未加载
voidlogicover 10 years ago
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:&#x2F;&#x2F;go.googlesource.com&#x2F;go&#x2F;+&#x2F;b3be360f16c44d21b2594d06e8d...</a>
twotwotwoover 10 years ago
Fixing the &quot;dot-dot-dot arguments always escape&quot; issue could in particular mean that logging code no longer risks making things escape even when it doesn&#x27;t run:<p><a href="http://stackoverflow.com/questions/27788813/variadic-functions-causing-unnecessary-heap-allocations-in-go" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;27788813&#x2F;variadic-functio...</a><p>...which would be cool.
tunesmithover 10 years ago
I keep on clicking on these Go headlines thinking they are about the board game. :-( I thought this was about flaws in a computer-go algorithm.
评论 #9041917 未加载
评论 #9042465 未加载
评论 #9042246 未加载