[Python-Dev] PATCH: attribute lookup caching for 2.6

Neil Toronto ntoronto at cs.byu.edu
Wed Dec 5 22:24:21 CET 2007

So Jim and PJE finally convinced me to do it the right way. :) Thanks 
guys - it turned out very nice.



It caches type/metatype attribute lookups, including missing attributes. 
Summary of the bug tracker issue:

- Successful attribute lookups are 20% faster, even for classes with 
short MROs and (probably most) builtins - haven't tested unsuccessful 

- Successful hasattr is 5-10% faster, unsuccessful is 5% faster (less 
impressive than above, and likely due to overhead - internally, all 
lookups are the same)

- list.__init__ and list().__init__ are slower, and I can't figure out 
why (creating instances of subclasses of list will be a little slower, 
and this may show up in other builtin types)

- I haven't benchmarked type attribute sets (how much do we care?) - it 
should be quite a bit faster than updating a slot, though

- Caching missing attributes is crucial for good performance

- The CreateNewInstances benchmark uncovered an issue that needs fixing; 
please see the tracker for details

All kinds of commentary and feedback is most welcome.


More information about the Python-Dev mailing list