by bsder · 8mo ago · 0 comments
That's not really true on modern architectures.
The "stack" is a way to time-alias memory and, on modern architectures, that also has performance implications. The stack gets pushed and popped repeatedly so that area of memory stays very hot in the caches.
Garbage collection, by definition, trashes locality. So, pushing onto the "stack" and unwinding it by "garbage collection" is pretty disastrous for performance on modern architectures.
No, it doesn't necessarily. It is correct if you are thinking about mark and sweep GC. But that is 50 years old. Generational GC has much better locality. And GC can even improve locality sometimes by moving objects together that are connected by references. I am not claiming that GC is always a big win for locality. That would be very far from the truth. On the other hand it is not by definition so, that locality is trashed by GC.