r/java • • Sep 18 '26

JVM Object immutability

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

4 comments sorted by

View all comments

3

u/Signal-Scholar1299 Sep 18 '26

I hope this falls within the scope of technical discussions.

4

u/agentoutlier Sep 18 '26

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.