Scalar replacement does not work even in very trivial cases: https://pkolaczk.github.io/overhead-of-optional/
In all those cases, Optionals were inlined, didn't escape, yet they haven't been properly optimized out.
Re:Go does not need a Java-style GC
by chrisseaton on Wednesday November 24, 2021 @07:16AM
(#29329220)
Did you understand why?
I don't know the exact reason here, but from my experience JVMs don't seem to perform optimisations as deep as static compilers. You can see the compiler not only missed scalar replacement here, but also didn't use a conditional move to avoid branching neither it performed any loop unrolling. Maybe it is because JITs are constrained by time and resources a lot more.
Re:Go does not need a Java-style GC
by chrisseaton on Wednesday November 24, 2021 @12:46PM
(#29332755)
It'd be worth doing a deep dive into this - you can look at the compiler's intermediate representation to understand why it didn't make an optimisation. There may be something trivial getting in the way.
It's worse than what Go has. Go can stack-allocate any struct and still pass pointers to it to non-inlined functions.