[ZODB-Dev] IIBTree.multiunion and list comprehensions

Christian Robottom Reis kiko at async.com.br
Tue Dec 9 14:43:51 EST 2003


[I've been messing around with optimizations to query results in
IndexedCatalog, and I've run into a result that's puzzled me a bit, but
since I'm now over it, I'm sharing here.]

ISTM that, when accessing a persisted BTree that holds Sets as
its values, using multiunion (I've tested in particular with IIBTree's
version) has no significant speed advantage over using a list
comprehension to glue the sets together. IOW, assuming tree is a
yet-to-be-unpersisted BTree with a large number of items stored,

    multiunion(tree.keys())

takes about the same time to run as

    [value for set in tree.keys() for value in set] (*)

My hypothesis is that even though multiunion() may run a bit faster,
we're bound by the retrieval of buckets from the persistence mechanism,
which is [comparatively] slow.

Note that multiunion returns an IISet(), while the latter returns a
list; converting between is pretty cheap given the context.

(*) In my case, it's '... in set.keys()' given that I'm using an
IITreeSet, but that's not important here.

Take care,
--
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 261 2331



More information about the ZODB-Dev mailing list