3 ms·
This might be a silly question but are there similar optimizations that apply to Java?
by etoulas 3y ago
This might be a silly question but are there similar optimizations that apply to Java?
- MrBuddyCasino 3y agoSome things you have no control over, like padding and alignment or explicit stack allocation (not counting non-managed memory / Unsafe). But the rest should apply just the same.
- winrid 3y agoWell it's kind of tough because the JVM does a lot of this for you! The JVM will try to pack "related" memory closer together. It can even do really cool things for tree structures (like a Node class) and linked lists - which is why you see java perform so well on these types of data structure benchmarks. In Java we have to worry about different things, like the number of fields on an object and object header sizes. A lot of advice in the article is still good to keep in mind when optimizing code on the JVM, though, like keeping frequently accessed fields next to each other.
- karelpeeters 3y agoThat sounds interesting, what does the JVM do for tree structures and linked lists? Is that just about compacting memory?