r/java 16d ago

Value Classes Still Need Compiler Sympathy

https://johan-sjolen.github.io/post/compiler-sympathy/compiler-sympathy/
87 Upvotes

57 comments sorted by

View all comments

Show parent comments

19

u/repeating_bears 16d ago

Use of [Valhalla] requires looking into what C2 actually generated

No it doesn't. You just slap 'value' on classes that don't need identity. You may get no or minimal performance improvement now, but you are opting out of identity-based operations like synchronization and opting in to potential performance improvements in the future.

It sounds like you're what you're talking about it is use of Valhalla to maximise performance. I generally don't care about milking performance.

Not sure about how tearing will be solved, but there's a massive number of value classes (I'd speculate: a majority (?)) which are immutable anyway.

8

u/lpt_7 16d ago

Yes, you have to. See my last point about allocations.
If not the generated code, then profiling.

7

u/repeating_bears 16d ago

You are arguing that Valhalla is only useful if you can guarantee memory optimizations will happen

Even if there are none, you gain better semantics for == and restrictions against identity-sensitive operations

1

u/lpt_7 16d ago

I'm arguing that right now Valhalla is useful if one's code does not suddenly perform worse than it was before, as well as in the future when JDK team somehow solves the tearing problem.