3 ms·
> (* Technically not all mutable objects live on the heap, because some never live at all, as they are optimized away so are never allocated in the first place.
by celrod 6y ago
> (* Technically not all mutable objects live on the heap, because some never live at all, as they are optimized away so are never allocated in the first place.)
The compiler will often stack allocate mutable objects in Julia. This is not the same as "never existed in the first place", because the stack pointer gets incremented and underlying data layout is you load from it is the same as that of the mutable object you allocated.
Here is one example where that's very obviously what's happening:
https://discourse.julialang.org/t/why-is-svector-faster-than-mvector/55174/10?u=elrod https://discourse.julialang.org/t/why-is-svector-faster-than...
But it can happen now generally with mutable structures that can't practically just live in registers.
- oxinabox 6y agofixed, to be more limitted in the claim
- celrod 6y agoCool, and fantastic summary! I enjoyed reading it.
- calebwinston 6y agoIf they are optimized away, are their destructors/finalizers still called? I'm really hoping the answer is yes...
- StefanKarpinski 6y agoYes, that is guaranteed.