News for hackers. Stuff that matters.
Re:Getting to Go: Garbage collection and runtime issues by ngrilly on Tuesday July 17, 2018 @05:07PM (#17553398)
> The write barriers you need reduce throughput, but they're ordinarily counterbalanced by the throughput gains you get from bump allocation.

Bump allocation significantly increases throughput only if you allocate a lot. If you don't, maybe you gain more by avoiding write barriers. And, as explained in the article, Go tends to allocate less because it is value-oriented (instead of reference-oriented, where most values are "boxed") and thanks to escape analysis.

Re:Getting to Go: Garbage collection and runtime issues by pcwalton on Tuesday July 17, 2018 @05:24PM (#17553550)
As the article also states, it's possible to remove those write barriers by hashing. I don't see any reason why it shouldn't be possible to use the same scheme for copying generational GC.

The most important point, though, is that you don't know whether the hypothesis that Go wouldn't benefit from generational GC is true until you test it. Nobody has tested it. And there is plenty of indirect evidence to suggest that this is not true. For one, Go programmers have a habit of manually microoptimizing short-lived allocations to keep escape analysis "happy", which is something that becomes much less important with bump allocation in the nursery. Another simple observation is that .NET has the same situation regarding value types as Go does, and .NET uses a copying generational garbage collector. A final observation is that certain situations, like indirect calls [1], cause objects to be spilled to the heap unconditionally.

[1]: https://github.com/golang/go/blob/964639cc338db650ccadeafb74...

Re:Getting to Go: Garbage collection and runtime issues by enneff on Tuesday July 17, 2018 @06:32PM (#17554075)
> Go programmers have a habit of manually microoptimizing short-lived allocations to keep escape analysis "happy"

I've been writing Go for 8+ years and have never done this, and I wouldn't approve a code review of a teammate that did this.

Re:Getting to Go: Garbage collection and runtime issues by pcwalton on Tuesday July 17, 2018 @06:33PM (#17554080)
But that's what the article says: "We started creating tools to help our users find objects that escaped and if it was minor they could make changes to the code and help the compiler allocate on the stack."
Re:Getting to Go: Garbage collection and runtime issues by enneff on Tuesday July 17, 2018 @07:22PM (#17554393)
"Tools used by a small minority of users to find performance issues," != "Go programmers have a habit of microoptimizations to avoid heap allocations." You are being disingenuous.
Re:Getting to Go: Garbage collection and runtime issues by ngrilly on Thursday July 19, 2018 @09:30AM (#17566058)
> The most important point, though, is that you don't know whether the hypothesis that Go wouldn't benefit from generational GC is true until you test it. Nobody has tested it.

I agree. But you would probably agree it would be a fairly difficult endeavour to test your hypothesis? To make a fair comparison, we'd need to implement an alternative version of the Go compiler and runtime, replacing the current GC with a copying generational GC, with a similar multi-year effort in optimizing and refining it.

Re:Getting to Go: Garbage collection and runtime issues by geodel on Tuesday July 17, 2018 @07:45PM (#17554504)
Copying will double memory overhead. So downside is easy to see for cloud applications.
Re:Getting to Go: Garbage collection and runtime issues by pcwalton on Tuesday July 17, 2018 @08:13PM (#17554640)
Only toy copying GCs are pure semispace collectors.
Re:Getting to Go: Garbage collection and runtime issues by mike_hearn on Tuesday July 17, 2018 @05:32PM (#17553632)
I would note that the JVM has done inter-procedural escape analysis for quite some time (via inlining) and the new Graal compiler does even more advanced inter-procedural escape analysis. In particular JVMs do not do stack allocation, they do something better called scalar replacement, which allows tricks like deleting variables from the middle of an scalar-replaced object. Effectively every field of the non-escaping object become local variables that can then be studied, removed, moved around etc. The talk says that Go doesn't do inter-procedural escape analysis at all.

Escape analysis and value types are both useful techniques, but they don't eliminate the need for a fast GC.

I would actually be quite interested in a study of whether equivalent Go/Java programs allocate more or less, especially when pitted against Graal. Presumably it's not hard to prepare such a test.