14 ms·
Everyone else: pauses are bad, we can’t have garbage collection. Java: pauses are bad, let’s make the garbage collector better. Much credit to the Java commun
by mnd999 5y ago
Everyone else: pauses are bad, we can’t have garbage collection.
Java: pauses are bad, let’s make the garbage collector better.
Much credit to the Java community for ignoring the noise and building something great that lets most applications have the best of both worlds.
- Semaphor 5y ago.NET is also regularly improving their GC, aren’t they?
- DougBTX 5y agoAlso notably Go, though really all GC languages which care about performance, of which there are quite a few.
- the8472 5y agoGo isn't playing in the same league though since their GC is non-generational and non-compacting. A lot of the difficulties implementing concurrent GCs comes from moving things between generations and compacting.
- DougBTX 5y agoI had this benchmark[0] in mind while writing the comment, though perhaps Go does well there by avoiding GC rather than having fast GC as-such? That would explain why its performance is close to the non-GC languages. [0] https://awesomeopensource.com/project/ixy-languages/ixy-languages https://awesomeopensource.com/project/ixy-languages/ixy-lang...
- throwaway894345 5y agoWithout digging into that benchmark, Go leans on stack allocation a lot more than many GC languages, and that’s a big part of why Go is able to achieve otherwise impressive performance. The same mechanism (idiomatic value types) that allows Go to elide GC in many cases also permits better cache coherency—there are fewer pointers into random regions of the heap so cache lines need to be flushed less frequently.
- stingraycharles 5y agoIs that a good or bad thing? What’s the trade-off being made here?
- 5e92cb50239222b 5y agohttps://blog.plan99.net/modern-garbage-collection-911ef4f8bd8e https://blog.plan99.net/modern-garbage-collection-911ef4f8bd...
- vips7L 5y agoThat article is beyond out of date when it comes to Java GC.
- throwaway894345 5y agoCompacting GC tends to have cheaper allocs and longer pauses (allocs need to be moved to different regions of memory and pointers to those allocs need to be rewritten to point to the new memory regions) while noncompacting has the opposite: slow allocations and small pause times.
- kaba0 5y agoThough many part of compaction can be moved to a parallel thread, can’t it? The actual stop-the-world time can be quite small that way (using read-barriers though)
- throwaway894345 5y agoI’m not so sure about barriers, but compacting requires rewriting pointers that are shared with the mutator threads, so it seems hard to parallelize.
- kaba0 5y agoAs far as I know, this is the “secret” of ZGC at least, it replaces the usual write barriers with read ones. So a parallel thread is free to move an object to a new place, and any thread trying to access it will at that point lock said object. This will have a performance impact (the usual write barriers have better throughput because they only “lock” when writing an object), but more of the GC can be parallelized. But I’m by no means anywhere close to an expert in the topic.
- isbvhodnvemrwvn 5y agoShenandoah is also not generational, at least the implementation I looked at a year ago wasn't.
- the8472 5y agoIt's region-based, the regions serve a similar purpose to generations but in a more granular fashion.
- Thaxll 5y agoThe problem is that there is not benchmark for GC, but from my experience the Go GC is very good, aka sub 1ms.
- SureshG 5y agoIs this the case very large go heaps? ZGC claims sub ms pause for TB heap size.
- pjmlp 5y agoNot only the GC, since version 7, most of the Midori stuff has been landing on C# (and to some extent F#), turning into a kind of "Managed C++". Contrary to the WebAssembly speech, CLR was one of the very first VMs to have support for C like languages, but those capabilities were only fully surfaced to the original Managed C++ (.NET 1.0) and C++/CLI (2.0 onwards). So now those capabilities are being exposed into C# as well. For example stack allocation of arrays is now also valid in safe contexts. You can apply using to any type that has Dispose() without inheriting from IDispose. Memory slices are now also a thing and native function pointers for example.
- kinjba11 5y ago> apply using to any type that has Dispose() without inheriting from IDisposable Last I saw, this was still being debated by the LDT and weighed against similar proposals such as introducing a `defer` keyword like Swift/Go.
- da_chicken 5y agoYes, although I'd say that .NET is still a little tied up with how fractured their environment is. There is a lot of tech debt sunk into the .Net Framework, and it'll be awhile before it really gets flushed away.
- Semaphor 5y ago> There is a lot of tech debt sunk into the .Net Framework I’m working on a website that has been growing since 1996… The chances of us ever migrating to .NET 5 and onwards is basically zero.
- sgt 5y agoWho is everyone else... Rust and Swift?
- WJW 5y agoC and C++?
- ncmncm 5y agoC++ and Rust.
- Zababa 5y agoI think it's mostly targeted at C or C++ users. Swift is garbage collected.
- sgt 5y agoIncorrect, Swift is not garbage collected. It uses reference counting. Read more here: https://docs.swift.org/swift-book/LanguageGuide/AutomaticReferenceCounting.html https://docs.swift.org/swift-book/LanguageGuide/AutomaticRef... As for C and C++, yes, of course. I meant "everyone else" as in the trendy new languages.
- saagarjha 5y agoReference counting is technically a form of garbage collection, FYI.
- sgt 5y agoReference counting deals with operations that have constant time, which I think puts it in a different category than what people normally view as GC.
- Zababa 5y agoI'm not sure that's true. Python mainly uses RC, yet most people think of Python as GC'd. I would argue that most people think that GC == automatic memory management.
- lmilcin 5y agoIt all depends on your application. I worked on one which was required to respond to a packet from the network within 5 microseconds of the packet arriving. Please, don't assume all applications are mobile uis, webapps and corporate backends.
- mnd999 5y agoI very deliberately wrote “most applications”. Of course there are exceptions.
- lmilcin 5y agoYour operating system you are running is not just "an exception". Neither is software running in all your electronics. All these require software that has some different requirements that typically are incompatible with unpredictability of a garbage collected dynamic language.
- kryptiskt 5y agoGarbage collection is the least of your problems in that case. You can't use a standard OS for that kind of scenario either, Linux has far bigger jitter than that. And if you have a hard real-time system, you could have a hard real-time garbage collector too. Garbage collection gets a bad rep from garbage collectors that are tuned for throughput rather than latency, but there is no lower limit to latency for garbage collection and there are GCs out there that prove it (like Azul). If you can afford dynamic memory allocation, you can afford garbage collection. And if you can't afford it, you can just preallocate and turn off the garbage collector.
- lmilcin 5y ago> You can't use a standard OS for that kind of scenario either, Linux has far bigger jitter than that. Bullshit. We were using Linux and it was just fine. But I agree, it requires more knowledge than your run of the mill software dev will ever have.
- 5y ago
- tpxl 5y agoI was testing ZGC the other day on my machine (24vcores, 64GB RAM) and it ate through about 4GB/s of garbage with about 10milisec of pauses over 220sec of runtime (24 threads doing nothing but allocations). G1 ate through about 2x as much garbage but with higher pause times. It's amazing how far we've come. I hope this means we can get more games in Java since I'd like to code one or two in my favorite language :)
- syspec 5y agoWasn't Minecraft written in Java?
- plainnoodles 5y agoYes, but as someone who ran a medium-sized server (200ish players), depending on what your map looked like, you occasionally found yourself spending a lot of time doing GC tuning, especially back in java 7 days when we didn't even have the first generation of G1GC. Ah, good times. I currently work in Hadoop and it's honestly stupid how much tuning a Spark job is like tuning a Minecraft server (from the JVM level anyway). Life's path is strange sometimes.
- U1F984 5y agoYes, the original Java edition is still in Java. There's now a C++ edition called bedrock as well.
- tpxl 5y agoYes, there are plenty of games written in Java, but afaik there are no big game engines written in it. I'd love to be proven wrong regarding this.
- ohgodplsno 5y agoIt was, although it got bitten at one update explicitly by the GC: entity positions moved from a bunch of arrays, to a single Position() class for each entity, leading to memory allocations that murdered performance. But then again, that's a problem you'd get without GC too, just maybe a bit less harsh/unpredictable.
- ncmncm 5y agoThanks, I still prefer exactly-zero ms pauses. Maybe that's just me, but I don't think so. And, I don't think I am giving anything up by skipping them.
- bloat 5y agoYou don't see any benefits to garbage collection at all? Would you even prefer to do your own memory management if you had a magic GC which never paused? I'd be interested in your reasoning if so.
- ncmncm 5y agoI'm perfectly happy to have all you lot depending on GC. And, I don't "do my own memory management". I just don't rely on a GC to do it.
- taejo 5y agoIt may be constructive to say what you do do, instead of leaving us to guess and telling us we're wrong.
- ncmncm 5y agoI mostly use "}".
- post-it 5y agoYou write programs so short and uncomplex that you rarely need to free memory?
- pwdisswordfish8 5y agoEver heard of RAII?
- 5y ago
- pjmlp 5y agoEveryone else: You can only have systems programming in languages with manual memory management. Java(JikesRVM)/Oberon/Go/D/Nim: Let rewrite the whole toolchain in X, including the memory manager itself.
- throwaway894345 5y agoEveryone else? Most languages have GC and Go has had a low latency GC for almost a decade IIRC.
- kaba0 5y agoIt is most definitely not low latency for heap sizes as big as what the OpenJDK can routinely handle (up to a terabyte). Go’s GC has it easier due to the language having native support for stack-based allocation which can sometimes be used in otherwise garbage-heavy places.
- throwaway894345 5y ago> It is most definitely not low latency for heap sizes as big as what the OpenJDK can routinely handle (up to a terabyte). A claim without evidence isn't worth very much. > Go’s GC has it easier due to the language having native support for stack-based allocation which can sometimes be used in otherwise garbage-heavy places. Java (i.e., "modern JVMs") also has "native" stack-based allocation (indeed, it has an escape analyzer whose sole purpose is putting things on the stack); however, it lacks value types.
- kaba0 5y agoYes it has escape analysis, but even if it were perfect and correctly recognize every possible pattern, it is still nothing compared to having native support for it in the language and mandate it’s usage throughout the codebase. One can easily add a single line and “break” the escape analysis, while it is compile time checked with value types.
- throwaway894345 5y agoGo doesn’t have semantics for stack allocation, it also has escape analysis. It’s pretty easy to intuit about the escape analysis, but you have to profile to be sure.
- native_samples 5y ago
- blub 5y agoJava's been making the garbage collector better for decades at this point and is still in the second performance tier compared to those other languages. Of course, if one does GC tuning like a pro, uses a sufficiently smart GC and maybe a custom VM (and unicorns) one may reach the mythical native speeds (typically at the cost of using a lot more memory).
- kaba0 5y agoTell me any runtime with a better performance than the JVM..
- voidnullnil 5y agoIt's more like this: C diehards: Pauses are bad, we need manual memory management. Everyone else: Does not have manual memory management.
- moonchild 5y ago> Does not have manual memory management That is a misunderstanding. If you would like to avoid pauses in c, you must be careful about how you allocate, what you put where, &c; you cannot simply use malloc and free. Similarly, if you would like to avoid pauses in a gc language, you must be careful about how you allocate, what you put where, &c; you cannot simply allocate. These techniques are actionable in any language. Java 'has' automatic memory management, but it also 'has' manual memory management (if you implement it).
- voidnullnil 5y agoNot without relying on implementation details.
- moonchild 5y ago? no In almost any language with automatic memory management, I can portably make my own freelists, regions, temporary (reused) buffers, ...