[Python-3000] Armin's attribute lookup caching for 3.0
Neil Toronto
ntoronto at cs.byu.edu
Fri Dec 7 20:14:32 CET 2007
I couldn't help myself. Such a beautiful thing had to be spread, and it
was *easy* to put it in 3.0 because types are simpler. A patch is here:
http://bugs.python.org/issue1568
If users are going to be encouraged to subclass from the ABC hierarchy
for new container and numeric types, they'll likely want something like
this. Both pybench and pystones are faster (pystones because its classes
are now instances of type), and those exercise attribute lookups on
classes with MROs no larger than 2. The pybench scores are good in
general (with all lookups very good), except SpecialClassAttribute,
which spends half its time doing class attribute assignments. Another
surprise is TryRaiseExcept - why should that be faster?
I found updating caches from setattr to be faster than invalidating
entries. (It could easily go back to invalidating all entries for a type
if that's preferred.) Adding extra TPFLAGS was unnecessary. It still
assumes attribute names are interned (it doesn't have to but it's a
little faster this way), but AFAIK this could only affect computed names.
Neil
More information about the Python-3000
mailing list