Hacker News new | ask | show | jobs
by masklinn 4860 days 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`)
1 comments

Which PyPy does, so __slots__ is entirely useless.
pypy 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.
The 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.