3 ms·
I think it's pretty obvious if you use these languages. A lot of things that require you to heap allocate in Java or Python (like classes!) have stack-allocated
by nicoburns 7y ago
I think it's pretty obvious if you use these languages. A lot of things that require you to heap allocate in Java or Python (like classes!) have stack-allocated versions in rust/c++. Which means that code which avoids slow heap allocation is much nicer than equiavlent code in Java that must avoid high level abstractions.
You're right that the GC isn't necessarily the issue. It's more the forced heap allocation which most GC languages come with.
- weberc2 7y agoAgreed, although to pick a nit (because it's an interesting nit IMO) "Classes" is orthogonal to allocation. In C++ you choose where you allocate your class and in Java the escape analyzer chooses for you. C# and Go have a GC and (more or less) semantics for heap-vs-stack allocation.
- xfer 7y agoThat heap allocation is most likely either optimized away and allocated in stack/ allocated in minor heap which is same as bumping a pointer just like in stack!
- weberc2 7y agoOnly for Java, not Python. And in any case, the cache performance will still be worse, but that’s a more minor cost.