[MERGE] Add an InventoryEntry cache for xml deserialization

Martin Pool mbp at canonical.com
Thu Dec 11 00:52:37 GMT 2008


On Wed, Dec 10, 2008 at 4:23 PM, John Arbash Meinel
<john at arbash-meinel.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Martin Pool wrote:
>> I was just wondering when reading about this if there'd be any value
>> putting items expired from the cache into a weakref, so they have a
>> chance of still being retained.  Or did we look into this before and
>> find that they were destroyed immediately anyhow?
>>
>
> If I was to do this I would probably just switch entirely to a
> WeakValueDictionary.
>
> The CPython garbage collector is deterministic if you don't have cycles.
> Though in these cases it will still be referenced by whatever other
> Inventory was recently deserialised.
>
> I'm not sure about the overhead of a WeakValueDictionary versus a normal
>  dictionary. Certainly a weakref object has at least a function-call
> overhead to evaluate whether the object still exists or not. (It may not
> be a large overhead.)

My point was to have a guarantee that at least N objects were retained
in the cache, and possibly more depending on how much more memory is
available, or at least so that they have a chance to be retained if
they're re-added before the gc kills them.  Secondly, it might mean
that the main objects are cheaper.  I think that when we looked into
it before it turned out that a plain WeakValueDictionary would not
hold them long enough for a cache to be useful.

-- 
Martin <http://launchpad.net/~mbp/>



More information about the bazaar mailing list