3 ms·
This all seems language and implementation specific. Comparing Go and Java, I have the general impression that garbage collection in Go has reached the point w
by skybrian 11y ago
This all seems language and implementation specific.
Comparing Go and Java, I have the general impression that garbage collection in Go has reached the point where it just works, while in Java we're still tuning it after all these years.
But part of the reason might be that creating garbage is more easily avoided in Go. Or it might that people are attempting different things.
- adrusi 11y agoI've been hearing (from other HN comments) that Go 1.6's GC is still considered less performant that hotspot's in the average case, and has significantly worse performance in some select edge cases. Historically Java competed with C++, and its evolution has been defined by trying to get it to match C++'s performance in the general case. Go prefers simple, sound and obvious to maximum performance.
- vvanders 11y agoJava is never going to compete with C++ until they have proper memory placement semantics. If I know how to arrange my data I can beat Java by 50x. The thing is so few people care(or need) this these days that stuff like the original article gets written.
- jerf 11y agoGo's garbage collection probably looks like it "just works" because the type of person who, in 2016, runs into a GC problem on Go will probably just rewrite it in Rust, rather than spend tens of thousands of dollars on a nonexistent best-of-breed Go compiler, the way you have that option for Java. So I don't think there's a lot of chatter about GC problems. There is some, but I think there's been more "I had a GC'ed language and switched to Rust and WOW! It was more work to write but the performance is blowing me away!" Go does have a couple of structural advantages over Java, such as shipping with "value types" on day one, and it's good enough for many uses. But that's probably not accurately described as "just working" in that sense.
- Manishearth 11y agoGo distinguishes at the type level between pointers and stack-based data, so it's much easier to have pervasive value types and only GC things which are being pointerified. Add escape analysis to that and it's amazing. Of course, there's a teensy-weensy mental cost that you have to pay in Go where you actually think about these pointers, since you have to explicitly add `&` and `*` for it to work well. This is far less than the cost required to think about malloc and free in C, but it's a cost, and part of the cost-benefit tradeoff between Go and Java. You have to think about pointers a little bit, and in return you get decently efficient memory management. Go's GC is basically "I will GC-manage what you ask me to and even then try to avoid it when possible" Java, on the other hand, doesn't distinguish between this and has to try and figure everything out itself. The programmer can't hint to the compiler that something doesn't need GC; the compiler has to figure this out on its own. This can't be changed backwards-compatibly, since it involves changing defaults. Java's GC is "I will GC-manage everything and sometimes try to avoid it"