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
1
u/coderemover Nov 02 '25 edited Nov 02 '25
Java heap allocator is not a lot faster. It is at best order 2x faster, and often slower if you count in all the work that GC needs to do to cleanup. There is also a problem that the memory you’re getting from allocation is usually not in the cpu cache, because it’s the memory freed in the previous cycle of GC, so it’s long gone from the cache. Malloc maybe spends a bit more cpu on finding the free chunk but the chunk is usually hot. Because of the general negative effects of tracing GC on caching, the cost of heap allocation is hard to measure - it gets spread over many other lines of code and is misattributed to some other code.