[ZODB-Dev] BTrees Bug?

Tim Peters tim at zope.com
Thu Feb 3 10:16:28 EST 2005


[Dieter Maurer]
>> In your concrete example: this would read:
>>
>>    for key in list(b.keys(0,3)): ...

[Chris Withers]
> Indeed, although am I correct in assuming tuple(b.keys(0,3)) would be
> marginally better from a memory and speed point of view?

The memory difference is real but trivial (maybe a dozen bytes total).  That
can be important when you have millions of sequences alive simultaneously,
but not when there's just one.  WRT speed, time both with actual app data,
and in context (there's no other answer to speed questions when two
approaches have identical O() behavior -- it all depends then on how
platform quirks affect low-level per-operation overheads).

> 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?

Give a specific, complete example of what you want to do.  Same as for
Python dicts, there are several patterns that might apply.  Toby explained
the most common one (accumulate change info in a non-mutating loop, and
apply changes in a second mutating loop).  If you read the brief doc section
I pointed at last time, then you already know that it's fine to mutate while
iterating if you're only changing the values associated with existing keys
(also a common case).



More information about the ZODB-Dev mailing list