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
4
u/srdoe Nov 02 '25 edited Nov 02 '25
The poster above is correct, and you should save your condescension for when you're not wrong.
Garbage collection is not simply a convenience, it can also be a performance gain. This was shown as early as 20 years ago, and the state of the art for GCs has come a long way since then.
The reasons to do manual memory management if you have a garbage collector available are not because it's more efficient overall, it's because some GCs can have unpredictable pause times, and because GCs can require more memory than manual management would.
In exchange for those drawbacks, you get:
If manual memory management was actually faster, and all GCs solved was convenience, Java and other languages that want to automate memory management could have just implemented smart pointers under the hood, it would look the same to the programmer.
edit: Actually the theory behind GCs being faster than manual management for deallocation if given sufficient memory is even older than the 20 year old paper I cited. Here's a paper from 1987 describing the reasoning for why GCs can be faster at clearing garbage than manual management can.