[Python-Dev] Caching tuple hashes

Raymond Hettinger raymond.hettinger at verizon.net
Mon Aug 4 03:51:29 EDT 2003


Strings save their hash values to avoid recomputation in subsequent
hashings.  In contrast, tuples recompute on every call.   I've googled
around and cannot find the rationale for this.  Some ideas are:

* the time to initialize and check the hash fields isn't repaid on average
* it isn't worth an extra structure field for storing the hash value
* C code can mutate immutables so there is a safety risk
* nobody ever thought of it (unlikely) or got around to it (more likely).


Raymond Hettinger



More information about the Python-Dev mailing list