3 ms·
If the deck is to be believed, it's not the garbage collector or the heap that's causing the performance loss, it's that APIs and algorithms they enable are all
by bcoates 14y ago
If the deck is to be believed, it's not the garbage collector or the heap that's causing the performance loss, it's that APIs and algorithms they enable are allocation-heavy compared to other "faster" languages.
Heap allocations are expensive even in non-GC languages.
- mzs 14y agoThe first example is lookup based on name, you can get away from that in python with slots but the common consensus is that it's not worth the performance improvement. That somehow translates into a dogma like, "Never use slots," but sometimes it is worth it.
- masklinn 14y ago> The first example is lookup based on name, you can get away from that in python with slots You can get away from that with a sufficiently smart JIT turning a stable access to a known object into little more than a vtable dispatch. That's close to what V8 does with hidden classes on full cache hits (object map — its "hidden class" — + object "array" property both cached). point.x will generate the assembly: cmp [ebx,<hidden class offset>],<cached hidden class> jne <inline cache miss> mov eax,[ebx, <cached x offset>] (where ebx is the previously loaded `point`)
- lucian1900 14y agoWhich PyPy does, so __slots__ is entirely useless.
- mzs 14y agopypy is great, but I and others used swig and am stuck now with maintaining that stuff. There is also memory benefit to slots for when there are many instances. Sometimes you just have to do gross stuff so you can get on to the next thing, it's okay when everybody understands it enough.
- lucian1900 14y agoThe memory benefit also exists on PyPy without slots. It may be possible to write a cffi backend for swig, but it's likely quite hard.