[issue9685] tuples should remember their hash value

Raymond Hettinger report at bugs.python.org
Thu Aug 26 00:04:16 CEST 2010


Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

Hello Tim! If you have a chance, please also take a look at issue9685 which I was planning to work on in the next couple of weeks.

For memoizing tuple hashes, I'm inclined to think the one extra field is worth it.  That would help all the cases where people are concerned about double accesses to dicts in a look-before-you-leap pattern or for a pattern of fetch-item-update-value-store-new-item.

It looks like the code for collections.OrderedDict() would benefit because it does multiple lookups and stores on the same key: http://svn.python.org/view/python/branches/release27-maint/Lib/collections.py?revision=84148&view=markup

It would also help the multiple lookups and stores in caching code such as that at http://code.activestate.com/recipes/498245-lru-and-lfu-cache-decorators

I suppose we could prepare a patch, instrument it, and try it with Twisted, SQLalchemy, and Django to find-out how many tuple hash calculations would be saved by memoizing.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9685>
_______________________________________


More information about the Python-bugs-list mailing list