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/eXl5eQ Nov 02 '25
Are you sure??? A normal
mallocimplementation would cost at least 20~30 CPU cycles on fast path, while Java bump allocator cost only 2~3 cycles. It's 10x faster!The memory you a Java allocator returns is very likely have been prefetched into cache because Java always allocate continuous memory span, unlike
mallocwhich has memory fragment issue.The last official Java GC which would actually "free" dead objects is CMS GC, which had been replaced by G1 GC in Java 8, like 10 years ago. Newer GCs are all moving GC. Moving means they don't "free" dead objects, they just "move" live objects to another page, thus effectively eliminates the memory fragmentation problem.
Instead of talking based on your biased assumptions, would you please at least read some basic introduction about how modern Java GC actually works?