repoze/repoze.lru — Issue #4: LRUCache.clock wastes RAM
Author: snordhausen
Created: 2012-01-13 13:09:23+00:00
State: open

The LRUCache.clock is a list of dictionaries, one dictionary for each cache entry. With 64 bit Linux + Python 2.7, an empty(!) cache with 10 million entries occupies 2.8 GB of RAM, because 10 million dictionaries are instantiated.

Since each dictionary has exactly two entries ("ref" and "key"), this could just as well be implemented using two list called LRUCache.clock_keys and LRUCache.clock_refs. This way, no dictionary is needed and RAM consumption for an empty cache with 10 million entries goes down to 158 MB (even that already includes what Python itself needs).