Russ Cox commented on a couple of the proposed fixes:
> Maybe after the compiler is converted to Go.
> 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.
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.
Vyukov and others have made some allocation-related changes that went by today in https://twitter.com/golang_cls (small maps and string-related buffers can now sometimes be stack-allocated, variables captured by closures less often need to be moved to the heap, and some other language constructs that used to allocate now don't). It figures that some stuff wouldn't be approved for 1.5; other changes are going on, and some compromise mostly seems like the cost of the regular release schedule they maintain.
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.
[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]
OK, why do I say that. Well:
- 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)
- You do get good payoff from stack allocation, in terms of time spent allocating and deallocating memory.
- The real payoff from EA is to allow synchronization removal in Java (which shouldnt matter for Go).
- 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.
- Stack allocation provides cheap deallocation, but not as cheap as a generational GC which can clear the young generation for very very cheap.
- Stack allocation also extends object lifetimes, which is bad.
- Stack allocation also allows you to move object fields into variables which can get values out of memory and into registers, which is good.
- Stack allocation also has worse locality than a good GC (a copying collector has amazing locality, putting things on the stack doesn't necessarily).
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.
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.
>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.
Garbage never generated is garbage never collected. Large enterprise Java apps often still have GC issues despite very advanced GCs to choose from. Also Go's GC is maturing slower than its escape analysis and its object pool (sync.Pool). Go is younger so its GC is weak compared to Java- but it does a good job using the stack and offers a state of the art object pool with thread local caching.
>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
Isn't this apples to oranges since one of these is a compile time expense and the other is a run time expense?
Your memory is bad :)
It's not very expensive to do escape analysis well.
Escape analysis is essentially a sub-problem of points-to analysis, with less resolution on the answers (The document actually points to why)
At worst, it is as expensive as points-to analysis, which, good ones, while N^3 in theory, are not in practice.
(they scale to millions of lines of code per second).
The points-to analysis I implemented for GCC, which is field sensitive, is N^3, but is run on every compile, and basically never shows up at the top of profiles. It is used to compute escape analysis results as well. It's not even state of the art anymore.
Alan Donovan wrote a go points-to analyzer for other reasons using the same algorithm but a better solver.
I'm not sure where you would ever get N^6, that sounds just truly horrible, and doesn't match any time bounds i'm aware of.
(flow-sensitive points-to is not even N^6, and context sensitive points-to are all 2^n theoretical worst case, even if they are not anywhere near that in practice anymore)
As for what to do, it's not a dichotomy.
They should do both :)
People whose expertise is GC/runtime are often not the same as whose expertise is in the algorithm/analysis side.
Stack allocation tends to have more predictable performance than GC. Being able to measure and reason about a function's performance may be better even if GC sometimes beats it on average.
That said, the Go developers are also working on making garbage collection more predictable. [1]
I think so, too. Java has had escape analysis for some years now[1]. It is not only used for stack allocation, but also for lock eliding. In any case, stack allocation has been found to not be a dramatic improvement under normal program circumstances precisely because young garbage is so cheap.
So all this, plus the details in the doc, imply that the Go GC isn't very good.
Just an amateur opinion:
I do not think Go the language is suitable for a copying collector and all GCs that are generational require copying (although it would be good to be wrong). This makes escape analysis a win.
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:
Ha, and a group of stones can "escape" capture in Go-the-game, and a Go-playing engine might even plausibly analyze whether some stones can escape. I dig it.
[+] [-] xdissent|11 years ago|reply
> Maybe after the compiler is converted to Go.
> 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.
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.
[+] [-] twotwotwo|11 years ago|reply
[+] [-] pbiggar|11 years ago|reply
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.
[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]
OK, why do I say that. Well:
- 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)
- You do get good payoff from stack allocation, in terms of time spent allocating and deallocating memory.
- The real payoff from EA is to allow synchronization removal in Java (which shouldnt matter for Go).
- 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.
- Stack allocation provides cheap deallocation, but not as cheap as a generational GC which can clear the young generation for very very cheap.
- Stack allocation also extends object lifetimes, which is bad.
- Stack allocation also allows you to move object fields into variables which can get values out of memory and into registers, which is good.
- Stack allocation also has worse locality than a good GC (a copying collector has amazing locality, putting things on the stack doesn't necessarily).
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.
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.
[disclaimer: please reread disclaimer above]
[+] [-] voidlogic|11 years ago|reply
Garbage never generated is garbage never collected. Large enterprise Java apps often still have GC issues despite very advanced GCs to choose from. Also Go's GC is maturing slower than its escape analysis and its object pool (sync.Pool). Go is younger so its GC is weak compared to Java- but it does a good job using the stack and offers a state of the art object pool with thread local caching.
>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
Isn't this apples to oranges since one of these is a compile time expense and the other is a run time expense?
[+] [-] DannyBee|11 years ago|reply
Escape analysis is essentially a sub-problem of points-to analysis, with less resolution on the answers (The document actually points to why)
At worst, it is as expensive as points-to analysis, which, good ones, while N^3 in theory, are not in practice. (they scale to millions of lines of code per second).
The points-to analysis I implemented for GCC, which is field sensitive, is N^3, but is run on every compile, and basically never shows up at the top of profiles. It is used to compute escape analysis results as well. It's not even state of the art anymore.
Alan Donovan wrote a go points-to analyzer for other reasons using the same algorithm but a better solver.
I'm not sure where you would ever get N^6, that sounds just truly horrible, and doesn't match any time bounds i'm aware of.
(flow-sensitive points-to is not even N^6, and context sensitive points-to are all 2^n theoretical worst case, even if they are not anywhere near that in practice anymore)
As for what to do, it's not a dichotomy. They should do both :)
People whose expertise is GC/runtime are often not the same as whose expertise is in the algorithm/analysis side.
[+] [-] skybrian|11 years ago|reply
That said, the Go developers are also working on making garbage collection more predictable. [1]
[1] http://golang.org/s/go14gc
[+] [-] pron|11 years ago|reply
[1]: https://wikis.oracle.com/display/HotSpotInternals/EscapeAnal...
[+] [-] papaf|11 years ago|reply
Just an amateur opinion:
I do not think Go the language is suitable for a copying collector and all GCs that are generational require copying (although it would be good to be wrong). This makes escape analysis a win.
[+] [-] voidlogic|11 years ago|reply
https://go.googlesource.com/go/+/b3be360f16c44d21b2594d06e8d...
[+] [-] twotwotwo|11 years ago|reply
http://stackoverflow.com/questions/27788813/variadic-functio...
...which would be cool.
[+] [-] tunesmith|11 years ago|reply
[+] [-] chc|11 years ago|reply
[+] [-] tree_of_item|11 years ago|reply
[+] [-] twotwotwo|11 years ago|reply