2 ms·
> Theoretically Java should be more memory efficient because it makes fewer guarantees and can move memory around. Java makes a lot of memory guarantees that a
by kllrnohj 6y ago
> Theoretically Java should be more memory efficient because it makes fewer guarantees and can move memory around.
Java makes a lot of memory guarantees that are hard to make efficient. Specifically in that it becomes extremely hard to have a scoped allocation. Escape analysis helps, but the nature of Java's GC'd + no value types means it's basically never good at memory efficiency. Memory performance can be theoretically good, but efficiency not really. That's just part of the tradeoff it's making. And nearly everything is behind a reference, making everything far larger than it could be.
Compaction helps reduce fragmentation, but it comes at the cost of necessarily doubling the size of everything being compacted. Only temporarily, but those high-water spikes are what kicks things to swap, too.