[ZODB-Dev] BTrees Bug?

Toby Dickenson tdickenson at devmail.geminidataloggers.co.uk
Thu Feb 3 03:27:37 EST 2005


On Thursday 03 February 2005 08:16, Chris Withers wrote:
> Dieter Maurer wrote:
> > In your concrete example: this would read:
> > 
> >    for key in list(b.keys(0,3)): ...
> 
> Indeed, although am I correct in assuming tuple(b.keys(0,3)) would be 
> marginally better from a memory and speed point of view?
> 
> My one concern about this is that I end up dragging a very long sequence 
> into memory, which is one of the things I use BTrees to avoid. Is there 
> a way this can be avoided (particularly when doing .items() or 
> .values()) or am I seeing a benefit which isn't really there in the  
> first place?

Your looping has to finish before your start changing the original object.

The converse solution to Dieters suggestion is to leave your loop control 
structures unchanged, but modify when you make the changes. Build a list 
describing the changes inside the loop (a list keys to delete, for example), 
and make those changes to the original object once your loop has completed.

-- 
Toby Dickenson


More information about the ZODB-Dev mailing list