News for hackers. Stuff that matters.
Re:For Better Computing, Liberate CPUs from Garbage Collection by pron on Thursday May 09, 2019 @03:49AM (#19866207)
I think that garbage collection has proven to be the best idea in programming languages in the past decades, and probably the only one that has made an impact at all. It's getting so good these days that few are willing to consider "moving on." In terms of throughput, it beats manual memory management (in fact, in principle, the cost of GC can be made arbitrarily low; a famous Andrew Appel paper shows how it can be cheaper than a stack), and in terms of latency we now have GCs with worst-case pauses of ~1ms on terabytes of heap, with an acceptable impact on throughput.

> Think about it, instead of finding a way of expressing when we're done with instances, we have a giant for loop that iterates over all of memory over and over and over to guess when we're done with things. What a mess!

It would be a mess if that's how modern GCs worked, but they don't. The problem with "expressing when we're done with instances" is that it's just wasteful, especially when concurrency is involved. This is one area of computing where the computer can offload a human task, and do so quite efficiently.

Re:For Better Computing, Liberate CPUs from Garbage Collection by dochtman on Thursday May 09, 2019 @04:06AM (#19866273)
Good throughput with GC seems to come with significant extra memory use:

"We compare explicit memory management to both copying and non-copying garbage collectors across a range of benchmarks using the oracular memory manager, and present real (non-simulated) runs that lend further validity to our results. These results quantify the time-space tradeoff of garbage collection: with five times as much memory, an Appel-style generational collector with a non-copying mature space matches the performance of reachability-based explicit memory management. With only three times as much memory, the collector runs on average 17% slower than explicit memory management. However, with only twice as much memory, garbage collection degrades performance by nearly 70%."

https://people.cs.umass.edu/~emery/pubs/gcvsmalloc.pdf

So you're still paying for it, just in a different dimension.

Re:For Better Computing, Liberate CPUs from Garbage Collection by pron on Thursday May 09, 2019 @04:15AM (#19866312)
> Good throughput with GC seems to come with significant extra memory use

Of course. RAM is the price we pay for GC. Good thing it's so cheap on servers.

BTW, just note that the paper doesn't compare GC (never mind that the algorithms have much improved since then) to real explicit memory management, but to an oracle (i.e. explicit memory management by an all-knowing God). Paying nothing other than for 3x RAM to get performance that's 17% worse than what God could achieve is a bargain, and why GC is considered one of the greatest success stories of modern computing.

Re:For Better Computing, Liberate CPUs from Garbage Collection by gpderetta on Thursday May 09, 2019 @05:18AM (#19866611)
Memory you are wasting for GC is Memory you are not using, for example, for caching which directly impacts performance.

Mind you, I think GC is great, but saying that RAM is free is misguided.

Re:For Better Computing, Liberate CPUs from Garbage Collection by bunderbunder on Thursday May 09, 2019 @09:51AM (#19868258)
FWIW, one mitigating factor is that GC isn't the only approach that wastes memory. You can also end up with memory waste in manual memory management. Due to heap fragmentation, for example, or retaining objects for longer than necessary due to programmer caution or error. I don't (personally) dare estimate their relative sizes, because I'm guessing a huge, perhaps dominant, share of differences in memory usage across languages is driven by features other than GC. Dynamic typing, for example.
Re:For Better Computing, Liberate CPUs from Garbage Collection by pron on Thursday May 09, 2019 @05:47AM (#19866727)
I didn't say it's free, only that it's relatively cheap. That RAM can simply be used for caching is incorrect, though. There are very-non-neglible costs to maintaining caches in distributed systems.
Re:For Better Computing, Liberate CPUs from Garbage Collection by benchaney on Thursday May 09, 2019 @10:57AM (#19868863)
It’s not clear what you mean by a distributed system in this context, but RAM is used for caching, costs or no.
Re:For Better Computing, Liberate CPUs from Garbage Collection by pron on Thursday May 09, 2019 @01:17PM (#19870143)
My point is that you can't increase the cache size indefinitely to get performance improvements, because you also have to handle cache invalidation. There is an optimal working set.
Re:For Better Computing, Liberate CPUs from Garbage Collection by imtringued on Thursday May 09, 2019 @05:25AM (#19866647)
Using RAM for "caching" sounds extremely wasteful. There could be applications that want to use it for something more useful than a 1% performance improvement.
Re:For Better Computing, Liberate CPUs from Garbage Collection by benchaney on Thursday May 09, 2019 @10:55AM (#19868838)
Caching is way more impactful than a 1% speed up. It is hard to know exactly, because it is impossible to disable on most modern operating systems, but I wouldn’t be surprised if it were an order of magnitude improvement in some situations.

By the way, caching doesn’t prevent RAM for being used by applications. If an application wants more memory, the os can always just evict some of the cache.

Re:For Better Computing, Liberate CPUs from Garbage Collection by rbehrends on Thursday May 09, 2019 @05:30AM (#19866664)
This is not only a dated paper (a decade and a half old), but it relies on assumptions that do not necessarily hold in practice.

If you test actual allocation performance on actual current day hardware, you may end up with completely different results, e.g.:

https://github.com/rbehrends/btree-alloc

Re:For Better Computing, Liberate CPUs from Garbage Collection by eru on Thursday May 09, 2019 @06:49AM (#19866980)
That's a very fresh repo. I wonder how GHC would fare. I guess I should contribute.
Re:For Better Computing, Liberate CPUs from Garbage Collection by rbehrends on Thursday May 09, 2019 @07:22AM (#19867136)
Thanks, but I do not plan to extend this project to other languages. I put it together a while ago as an illustration that conventional wisdom regarding GC cost is not what many people think.

If I were to expand it, I'd look at other allocation patterns rather than more languages; I've already good a fairly good cross-section of garbage collectors and malloc() implementations, so I don't really need any more.

Re:For Better Computing, Liberate CPUs from Garbage Collection by eru on Thursday May 09, 2019 @07:41AM (#19867257)
Fair enough. Well, too late, I just hacked together a Haskell version based on the OCaml version. It's naive code, but 16 times faster (0.235s vs 3.818s).

So I expect some GHC specific optimizations are kicking in. Eg GHC is probably smart enough never to construct the whole tree at once. Whether that counts as the kind of static analysis static of object lifetimes someones else in this thread talked about or not, I don't know.

Update: I think it's just common subexpression elimination kicking in..

Re:For Better Computing, Liberate CPUs from Garbage Collection by eru on Thursday May 09, 2019 @06:47AM (#19866965)
> I think that garbage collection has proven to be the best idea in programming languages in the past decades, and probably the only one that has made an impact at all.

Depends on how you set your thresholds. Paying more attention to side-effects / purity / const has been pretty useful, too. And so have mainstream languages adopting first class functions. And making it easy to compose data structures. (Compare eg how Python allows you to return essentially two values via a tuple, and how cumbersome the same tasks is in Java; so people are tempted to use side-effects instead.)

Re:For Better Computing, Liberate CPUs from Garbage Collection by pron on Thursday May 09, 2019 @06:57AM (#19867025)
> Paying more attention to side-effects / purity / const has been pretty useful, too...

I don't know. Studies haven't been able to find any big effects, and the industry isn't seeing them, either. You may like those things, but unlike GCs, it doesn't seem like they've made a real impact.

Re:For Better Computing, Liberate CPUs from Garbage Collection by eru on Tuesday May 14, 2019 @11:58AM (#19910719)
Interesting. Do you have links to these studies? Thanks!
Re:For Better Computing, Liberate CPUs from Garbage Collection by cpach on Thursday May 09, 2019 @05:26AM (#19866650)
If anyone is interested in reading the paper, it’s available at this FTP server: ftp://ftp.cs.princeton.edu/reports/1986/045.pdf