[Python-Dev] PATCH: attribute lookup caching for 2.6
ntoronto at cs.byu.edu
Thu Dec 6 07:35:10 CET 2007
Phillip J. Eby wrote:
> At 07:43 PM 12/5/2007 -0700, Neil Toronto wrote:
>> FWIW, I like it. Though the hash should really incorporate the hash of
>> the type name as well as the attribute's so that sometype.method calling
>> othertype.method doesn't invalidate the cache. Locality makes the global
>> cache work, but locality also often means re-using the same names.
> Look at the patch more closely. The hash function uses a version number
> times the method name's hash. "Version" numbers are assigned one per
> class, so unless there are 2**32 classes in the system, they are
> uniquely numbered. The multiplication and use of the high bits should
> tend to spread the hash locations around and avoid same-name collisions.
Good grief - how did I miss that? I plead parenthesis. They threw me off.
So I've applied Armin's patch to 2.6 (it was nearly clean) and am
playing with it. cls.name lookups are 15-20% faster than mine, and
inst.name lookups are 5-10% faster. His is also winning on hasattr calls
(succeeding and failing) on classes, but mine is winning on hasattr
calls on instances. I want to poke at it a bit to find out why.
On pybench, his is faster at BuiltinMethodLookups, significantly faster
at CreateNewInstances, and a bit faster at almost everything else.
BuiltinFunctionCalls is slower - slower than stock - it might need
poking there, too.
In all, it's a lovely piece of work.
More information about the Python-Dev