News for hackers. Stuff that matters.
Re:Go does not need a Java-style GC by mappu on Tuesday November 23, 2021 @04:26PM (#29323773)
"Scalar replacement" explodes the object into its class member variables and does not construct a class object at all. That does result in the exact same `sub %esp` (that Go would do for any struct), but it is restricted to only working if every single usage of that class type is fully inlined and the class is never passed anywhere that needs it in its object form.

It's worse than what Go has. Go can stack-allocate any struct and still pass pointers to it to non-inlined functions.

Re:Go does not need a Java-style GC by pkolaczk on Tuesday November 23, 2021 @05:02PM (#29324132)
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?
Re:Go does not need a Java-style GC by pkolaczk on Wednesday November 24, 2021 @12:08PM (#29332277)
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.