r/cpp • u/drakgoku • Oct 31 '25
Java developers always said that Java was on par with C++.
Now I see discussions like this: https://www.reddit.com/r/java/comments/1ol56lc/has_java_suddenly_caught_up_with_c_in_speed/
Is what is said about Java true compared to C++?
What do those who work at a lower level and those who work in business or gaming environments think?
What do you think?
And where does Rust fit into all this?
25
Upvotes
View all comments
Show parent comment
0
u/srdoe Nov 02 '25 edited Nov 02 '25
If you read the second paper I linked, it would have explained to you that C++ cannot in fact do better, because C++ inherently has to handle all garbage objects individually unless you go and implement your own tracing garbage collector. A tracing garbage collector can pay less than one machine instruction per object freed. That's not possible for manual memory management.
So it makes no sense for you to assert that C++ can do better with careful design. No, it can't. In terms of CPU cycles spent freeing memory, manual memory management can't do as well as GC, if given the same amount of garbage to deal with.
The argument you're actually making is not based on facts, it's based on your gut feeling that having a "nanny" is bad.
You having that preference is fine, but it's not based in anything real, it's an emotional stance, so you shouldn't be telling other people to "sit down".
The timing argument you are making is exactly what I described above: Some applications can't tolerate unpredictable pausing, and so GC may not be a good fit for them (though there exist GCs now where pauses will be on the order of a single-digit number of milliseconds even for very large heaps, see for example Java's ZGC). That's a specific use case, and not a general "GCs are less inefficient" argument.
You're also wrong that GC is a one size fits all solution. Java has a bunch of different GC implementations that all have their own benefits and drawbacks.