[Python-3000] Armin's attribute lookup caching for 3.0

Neil Toronto ntoronto at cs.byu.edu
Fri Dec 7 23:17:36 CET 2007


Neil Toronto wrote:
> Phillip J. Eby wrote:
>> That having been said, the idea that the statement 'SomeBaseClass.foo = 
>> 23' is actually going to walk through cache entries and invoke a 
>> callback for *every* subclass of SomeBaseClass in the program makes me a 
>> tiny bit nervous.
>>
>> On the other hand, I suppose it's also a good argument for not using 
>> class attributes when you really want a global.  :)
> 
> Heh. You never know what those crazy users will need to do. You of all 
> people should know that. :p
> 
> If it's too slow, an obvious way to speed it up is to not use 
> update_subclasses and avoid the overhead. Besides avoiding calling a 
> function by pointer, not doing the shadowing check may also be faster 
> generally, since, as you say, assigned attributes are most likely 1) not 
> shadowed (they'll almost never be methods), or 2) in a leaf class. It 
> may be that Armin's invalidate everything approach would be generally 
> faster that way because it *can* skip shadowed attributes. To update you 
> have to check for shadowing.
> 
> I may try it. I couldn't say whether it's worth duplicating the code.

Okay, I tried it. SpecialClassAttribute sees a 3% speedup but 
NormalClassAttribute sees a 9% slowdown. I haven't got a clue what that 
asymmetry is all about.

At any rate, I'll #ifdef it and post a new patch. It's yet another thing 
to play with.

Neil


More information about the Python-3000 mailing list