I don't know much about this, but upthread various people say that scalar replacement happens very rarely if at all, currently. E.g.: https://news.ycombinator.com/item?id=29324132.
Could you perhaps comment on that, since you seem to have experience?
The issue is not that it doesn't happen - it does, all the time. The problem is it's unpredictable, hard to control and hard to measure. So it's sort of magic that gets blurred into all the other optimizations the VM is doing, and refactoring your code can make the difference between it happening or not.
First of all that blog post is wrong, it uses Optional which isn't a value type to start with, and contains internal fields.
It is considered a value like class, that will eventually be turned into a value type when Valhala arrives, until then there are no guarantees in scalar replacement.
Secondly, GraalVM or Azul are much better at it, which the author didn't bother to try their blog post on.
Could you perhaps comment on that, since you seem to have experience?