News for hackers. Stuff that matters.
Re:Go GC: Solving the Latency Problem in Go 1.5 by rurban on Thursday July 09, 2015 @02:04AM (#9856377)
> I just don't really understand why people continue to work on garbage collection. > ... but I think it's time to walk away from GC

Well, look at the arguments. GC advantages:

  * less memory (unless you use a semi-space GC)
  * faster
  * can handle cyclic refs (graphs, not only trees and linked lists)
  * trivial to use, less programmer errors
What you got wrong: significant memory and CPU overhead.

If you compare the memory overhead and complexity of refcounts with malloc to a non-semi-space GC, you'll be surprised. malloc is more complex and worse in it's CPU overhead, refcounts in every data cell are a huge overhead. GC's got it better.

Where GC's have a memory overhead (copying collectors), they do it on purpose, on machines which do have enough memory. Those copying collectors are the fastest, but cannot be used on small devices. With not enough RAM, you just use a trivial Mark&Sweep, which is much more trivial than your malloc implementation and manual refcounts.

The only real field where you cannot use a GC is, when you cannot tolerate pauses, as in real-time, latency critical apps. But even there exist incremental GC's (like boehm) with real-time characteristics. And when you need immediate destruction of objects, when they go out of scope, and not when the GC decides to destroy them later on. This can be solved by the compiler, but usually isn't.

Of course people always walk away from GC and avoid it like a plague. GC people on the other hand feel memory is too important to be trusted to programmers. We had these discussion for decades.

Re:Go GC: Solving the Latency Problem in Go 1.5 by crafn on Thursday July 09, 2015 @02:51AM (#9856504)
From gamedev perspective:

Every time I've prototyped something on a GC'd language (java, actionscript, javascript, ..) I soon find myself optimizing memory allocations and not making the game because the GC causes too much overhead and/or causes too long pauses and therefore makes the game feel miserable. It doesn't matter if there are some theoretical GC models which have < 1ms pauses with gigabytes of heap data, as the current implementations don't seem to be anywhere near that.

Nowadays I prefer to use C not because I like malloc, but because it makes handling different memory allocation schemes trivial (unlike C++). Furthermore, in this semi-real-time case the performance of malloc is irrelevant because when you want to be fast and low-latency, you pre-allocate everything and use lightweight functions to further distribute memory from those blocks.

In conclusion, I've found that manual memory management lets me focus more on the task I have in hand while GC don't.

Re:Go GC: Solving the Latency Problem in Go 1.5 by pjmlp on Thursday July 09, 2015 @04:39AM (#9856774)
I bet it only works, because you work in small teams with highly skilled developers.
Re:Go GC: Solving the Latency Problem in Go 1.5 by pcwalton on Thursday July 09, 2015 @02:20AM (#9856416)
Most of the complexity of a good malloc (jemalloc/tcmalloc) is going to be in its thread-local caches and in its placement heuristics, both of which are also necessary for a good GC (for the tenured generation, in the latter case). Accounting necessary for the tenured generation is also comparable to accounting for a malloc implementation. Fragmentation also isn't much of an issue anymore with modern allocation schemes. When you add in the complexity and overhead of tri-color marking and write/read barriers, the overhead often isn't in GC's favor, compared to a well-tuned program that uses the stack where possible and a good malloc implementation for long-lived objects only.
Re:Go GC: Solving the Latency Problem in Go 1.5 by MrBuddyCasino on Thursday July 09, 2015 @05:29AM (#9856925)
Also, Azul Systems solved that issue - the proprietary C4 GC has no pauses, and the heap can be huge, like hundreds of GB. If that tech would become common place, maybe this discussion would be obsolete. But I think C4 requires kernel support, and the first attempt to get a patch accepted didn't go well.
Re:Go GC: Solving the Latency Problem in Go 1.5 by osi on Thursday July 09, 2015 @08:54AM (#9857530)
To clarify, Azul's Zing does have pauses, but they optimized the crap out of them (the pauses are more time-to-safepoint rather than GC pauses). GC time wrt application stopped time is constant regardless of heap size.

(I'm an Azul customer and Zing user)

Re:Go GC: Solving the Latency Problem in Go 1.5 by MrBuddyCasino on Thursday July 09, 2015 @09:00AM (#9857552)
Thanks, the marketing implies its pause-less. What are typical application stop times?
Re:Go GC: Solving the Latency Problem in Go 1.5 by osi on Thursday July 09, 2015 @09:39AM (#9857765)
My mean pauses are a few hundred micros. Standard deviation is slightly more (300-500 micros), with a max of a millisecond or two.
Re:Go GC: Solving the Latency Problem in Go 1.5 by pcwalton on Thursday July 09, 2015 @01:01PM (#9859172)
Azul also sacrifices throughput over the HotSpot GC to achieve very low pause times—the overhead of a GC is not just in its pause times! There's no free lunch.
Re:Go GC: Solving the Latency Problem in Go 1.5 by blub on Thursday July 09, 2015 @05:34AM (#9856945)
YES, if you take all the pluses form multiple types of GC, it's gonna look awesome. In reality you have one GC; if you're lucky maybe your toolchain supports multiple and you can swap them.

So discussion about "GC" in the abstract are useless, discussion about the GC in Go 1.5 are absolutely worth it, and then you can find real-world stories about GC failures.

Re:Go GC: Solving the Latency Problem in Go 1.5 by fauigerzigerk on Thursday July 09, 2015 @05:21AM (#9856898)
Can you point me to the source of your claim about memory overhead? The Go team specifically states their goals for the 1.5 garbage collector as follows:

"Hardware provisioning should allow for in-memory heap sizes twice as large as reachable memory and 25% of CPU cycles". http://llvm.cc/t/go-1-4-garbage-collection-plan-and-roadmap-...

As far as I know, that collector is not a copying collector. I also know that all JDK GCs have significant memory overhead (not sure about the Azul one).

Re:Go GC: Solving the Latency Problem in Go 1.5 by rurban on Thursday July 09, 2015 @08:34AM (#9857446)
They are still using a simple and slow GC, non-copying, tri-color M&S, but at least incremental.

So they need to scan the complete heap, while a good copying collector (e.g. a two-finger Cheney with forwarding pointers) would only need to scan the stack and some roots. My GC needs ~4ms on normal heap sizes, the fastest M&S GC's need ~150ms. But I haven't found a good version besides the Azul one, which works fine threaded.

Memory overhead: A non-copying GC has none. Lookup a GC book or explanation. Refcounts have plenty: 1 word per object. malloc has plenty for its free-list management, growing with the heap size.

A semi-space GC is different as it reserves for every heap segment a mirror segment. A fast version reserves max heap and divides it by 2, so can use max 2GB of 4GB. A normal version can do that incrementally.

Java has a huge memory overhead from the kernel and run-time alone, not so the GC, but since they have various swappable GC's you need space for that. You can write better and smaller run-times with GC which do run circles around Java, .NET, Go or Ruby. As I said mine needs ~4ms, the fastest java is ~20 - 150ms. v8 has a good one, but I don't know their stats out of my head.

Re:Go GC: Solving the Latency Problem in Go 1.5 by fauigerzigerk on Thursday July 09, 2015 @10:41AM (#9858077)
>Memory overhead: A non-copying GC has none

Do you have any idea what could make the Go folks ask for "in-memory heap sizes twice as large as reachable memory"? This seems to be completely at odds with what you are saying.

Re:Go GC: Solving the Latency Problem in Go 1.5 by rurban on Thursday July 09, 2015 @11:59AM (#9858676)
Why? Reserving virtual memory has nothing to do with actual memory usage.
Re:Go GC: Solving the Latency Problem in Go 1.5 by fauigerzigerk on Thursday July 09, 2015 @01:28PM (#9859361)
It would be great if they really mean virtual memory, but I very much doubt it as it makes no sense as a goal and is inconsistent with mentioning "Hardware provisioning".