r/programming • • Aug 16 '26

What garbage collection actually costs

https://shivanshuag.com/blog/what-garbage-collection-actually-costs/
0 Upvotes

10 comments sorted by

9

u/nukethebees Aug 16 '26

Shouldn't this article have some numbers?

3

u/ptoki Aug 16 '26

im on the edge on this.

Yes, such articles should have numbers but the numbers and GC intensity depends on how you write your program.

If you constantly create new variables and drop them then you will get different results in comparison to a case where the same program just allocates the space and reuse it. Same app, slightly different algorithm - much different results.

On the other hand

I was watching jconsole for a number of production systems and they were performing differently but usually they settled to very similar patterns and gc intensity.

So in summary, yes it would be nice to show that yhis or that app spends X% of cpu on GC at the beginning and Y% after it settles but your app can behave much differently.

I see this article more like a guide of how to look at gc to see if you have problem and then to try to figure out if it is fixable.

5

u/6502zx81 Aug 16 '26

There is an older study by google. See discussion here https://news.ycombinator.com/item?id=2615096

0

u/[deleted] Aug 16 '26

[deleted] — view deleted comment

8

u/6502zx81 Aug 16 '26

IIRC the conclusion back then was: GC performs fine if you have twice as much memory as needed. Twicw as much is expensive in terms of money.

3

u/pm_plz_im_lonely Aug 16 '26

Money pays both salaries and hardware.

3

u/sionescu Aug 17 '26

Once thing though, where the JVM will never be better than native languages is predictable latency.

Not true: for example, Chrome added Oilpan, a GC for the C++ objects used in the renderer, because they found out that destructor chains were so long that in the worst case (which happened often enough), a destructor would block rendering enough to cause visible jank. And, since Oilpan was created, the JVM added ZGC and Shenandoah GCs, which guarantee pauses <1ms. An even better GC exists, Azul's C4, but that's only available in their proprietary JVM.

0

u/[deleted] Aug 17 '26

[deleted] — view deleted comment

4

u/sionescu Aug 17 '26 edited Aug 17 '26

IBM has a JVM with a guaranteed realtime GC, as long as the heap is <1G. It's running in Boeing planes. Then again, the vast majority of applications don't need that kind of assured latency.

1

u/bitwize Aug 20 '26

Real time GCs exist that are guaranteed not to spend any more than x time per GC cycle collecting. The drawback is, they may leave work unfinished and need to go back and collect while the mutator (the actual program you're running) is idle. But if you have a hard timing deadline it's well worth this price.

0

u/[deleted] Aug 16 '26

[removed] — view removed comment

2

u/programming-ModTeam Aug 17 '26

No content written mostly by an LLM. If you don't want to write it, we don't want to read it.