[Python-Dev] Add a frozendict builtin type (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Thu Mar 1 14:34:56 CET 2012


On Thu, Mar 1, 2012 at 7:29 PM, André Malo <nd at perlig.de> wrote:

- Caching. My data container objects (say, resultsets from a db or something)  usually inherit from list or dict (sometimes also set) and are cached  heavily. In order to ensure that they are not modified (accidentially), I  have to choices: deepcopy or immutability. deepcopy is so expensive, that  it's often cheaper to just leave out the cache. So I use immutability. (oh  well, the objects are further restricted with slots)

Speaking of caching - functools.lru_cache currently has to do a fair bit of work in order to correctly cache keyword arguments. It's obviously a solvable problem even without frozendict in the collections module (it just stores the dict contents as a sorted tuple of 2-tuples), but it would still be interesting to compare the readability, speed and memory consumption differences of a version of lru_cache that used frozendict to cache the keyword arguments instead.

Cheers, Nick.

-- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-Dev mailing list