News for hackers. Stuff that matters.
Re:.NET 6 vs .NET 5 speedup by kaba0 on Monday November 22, 2021 @06:41AM (#29305323)
If garbage collection happens on a separate thread, and makes allocation much faster, is it really “slower”? You have to call malloc which will try to defragment your memory, and then later you will have to call free. Those block the calling thread, if anything, for certain problems they are slower than GC.
Re:.NET 6 vs .NET 5 speedup by ygra on Monday November 22, 2021 @05:09PM (#29312120)
Garbage collection itself isn't really slow, per se. But allocating a lot of short-lived objects on the heap still means that a lot of objects have to be reclaimed fairly frequently. And at least .NET's garbage collector isn't able to do all that without pauses. And those add up.

But even if the GC is really concurrent: If there's a way of not doing that work it's still better, IMHO.

One interesting profile I've seen at work recently spent about 30 % creating objects, and another 35 % in garbage collection (of pretty much the same objects that have been created all the time). So if there was a way of not allocating that much, or not doing it on the heap, the algorithm could be about twice as fast.

Re:.NET 6 vs .NET 5 speedup by kaba0 on Wednesday November 24, 2021 @03:55PM (#29335043)
But comparing it to not doing that work is somewhat dishonest — for that you use compare a malloc for each call and a destructor at the end of the scope — and surprisingly, malloc will often do much worse than a good GC implementation, with trying to defragment a bit, etc.

Also, Java can often accumulate big heaps because it only runs the GC when it absolutely must — as you mentioned, it would be unnecessarily work otherwise. It might be interesting to mention that OpenJDK is the “greenest” out of the managed languages due to that.