by chrisseaton · 4y ago · 0 comments
Because the objects are self-describing - they have a class which tells you their size.
object_a = tlab
object_a.class = ClassA
object_b = tlab + 8
object_b.class = ClassB
object_c = tlab + 16
object_c.class = ClassC
tlab += 48
check tlab limitYou’re extremely knowledgeable on all this, so I’m sure that nothing I’m saying is surprising to you. I don’t understand why you seem to be arguing that heap allocating everything is a good thing. It is certainly more expensive than stack allocation, even if it is impressively optimized. Heap allocating as little as necessary is still beneficial.
You may be confusing with scalar replacement of aggregates, which is a separate concept.
The only time Go has anything like a class pointer for any object on the stack is in the case of something cast to an interface, because interface objects carry metadata around with them.
These days, Go doesn’t even stack allocate all non-escaping local variables… sometimes they will exist only within registers! Even better than the stack.
Did you read the article I linked? That's what it says - and this isn't stack allocation, it's SRA. Even 'registers' is overly constrained - they're dataflow edges.