News for hackers. Stuff that matters.
Re:Redesigning Python's named tuples by chubot on Saturday September 02, 2017 @02:18AM (#15154608)
Hm I did a test with an coverage-instrumented Python binary, and you are right.

I counted the number of times lookdict_string in dictobject.c is called -- call that number D. And then I made N attribute accesses like 'p.x'.

Without slots, if N goes up, then D goes up. With slots, as N goes up, D stays constant.

Thanks for the information -- I'll look into this more.

(However, as mentioned, slots are not more than 20-30% faster on my machine, in this limited benchmark. I feel like this is a double mystery. Or maybe it's just that interpreter loop overhead or some other overhead is the bottleneck, and not dict access.)

Re:Redesigning Python's named tuples by chubot on Saturday September 02, 2017 @12:48PM (#15156953)
I'm talking to myself at this point, but I think the problem with the caching is that every attribute lookup p.x has to consult the type, not just the object. That's not true in Java.

So you avoid the dictionary lookup, but you're still following extra pointers.