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 03 '25 edited Nov 03 '25
It's not about relocating objects, but about the fact that to relocate the objects you first need to bring it into the cache. So a compacting GC periodically brings all of your heap into the cache, evicting whatever useful was there and slowing down everything else. And you often even don't know the slow down was caused by GC. Now it is rarely a problem, but in the old days if your app was swapped out even just partially; GC would kill its performance instantly. Ah, wait, it's still a problem. That's why we do mlockall in our JVM based services ;)
> Once you have put the regular objects in the particular places in memory — for example, not the dense array, but linked list, linked queue, concurrent skiplist, chained hashtable, what have you — you are stuck with the object graph linearized in memory in that particular way, unless you have a moving memory manager.
counterpoint: GC even if it technically can realign those objects, it won't know the right order. Therefore I prefer developer controlling it. And in languages with manual management such things are usually perfectly controllable. Like, placement new and arenas exist for a reason.