logoalt Hacker News

What garbage collection actually costs

13 pointsby shivanshuaglast Sunday at 10:05 PM22 commentsview on HN

Comments

kazinatortoday at 3:36 PM

> Think of a service that keeps a large cache in memory, or an index built out of millions of small objects that all point at each other. Every one of those pointers has to be followed on every cycle, for as long as the process is up.

That's a strange thing to assert, having acknowledged the existence of generational GC.

220hertztoday at 2:37 PM

I used to write a lot of Javascript-like Extendscript scripts back when I was using InDesign a lot. The DOM's global object $ had a method to directly invoke the garbage collector. It made a difference certainly, but it was difficult to tell to what extent because InDesign itself gradually leaks memory and becomes more bloated the longer you use it in a single session.

bjournetoday at 3:26 PM

Props for using a correct nomenclature. Reference counting is a "kind of automatic garbage collection. Tracing garbage collection is also a kind of automatic garbage collection.

shivanshuaglast Sunday at 11:57 PM

Agreed, for most real world softwares, the cost of GC is irrelevant. But there are still some programs like databases or game engines where the cost can start adding up. That's when you measure and optimize.

show 3 replies
miladyincontrollast Sunday at 11:05 PM

What does GC cost? For Caddy with an incredibly synthetic http only benchmark it costs about 2ms of latency and somewhat less throughput. Worth it in an incredibly artificial benchmark? Perhaps. However when it comes to real world usage the cost is a significantly smaller piece of the pie.

thomashabets2today at 2:44 PM

> In Rust you pay for it by arranging your program in a way the compiler can verify.

I disagree with this. The sentence implies that this work is done in order to make the compiler happy, where my experience is that it forces the programmer to actually get it right.

I had an "aha moment" when I was frustrated at failing to express my intent to the compiler, and suddenly realised that the reason I couldn't "just say the magic words" was that my object ownership design was inherently flawed. I had to make large changes not to make the compiler happy, but to actually have a coherent design.

So no, it's not about what "the compiler can verify". That's like saying "my lawyer won't let me do this". No, your lawyer is your employee, not your boss. They're just saying that if you do this, then you may go to prison. It's not the same thing.

("unsafe" is the Rust way to go "thank you, legal department, but I'm making a business decision to take this risk. Your concern has been noted")

show 2 replies
pclowestoday at 2:31 PM

This is one of the best high-level survey explanations of GC I have seen, nice work.

amazingamazingtoday at 2:54 PM

I rarely see a real use case bottle necked on garbage collection.

EGregtoday at 2:47 PM

There is no need for garbage collection if you don’t form circular references. Just have a canonical direction and always keep weak references the other way.

show 1 reply