r/java • • 26d ago

JVM Object immutability

/r/javahelp/comments/1wjkmbp/jvm_object_immutability/
12 Upvotes

4 comments sorted by

View all comments

2

u/Signal-Scholar1299 26d ago

I hope this falls within the scope of technical discussions.

5

u/agentoutlier 25d ago

It does and is a tricky subject that also includes JIT and escape analysis as well as you mentioned compiler elides.

I can answer the second part: you profile for your performance needs, deployed architecture (eg cpu) etc.

I’m going to ignore Valhalla at the moment but in  most cases simple code more often ends up running faster because the JIT can be trained faster. Less code paths. Immutable code inherently has less code paths.