[CDBI] Re: Trouble with Perl's reverse function

Edward J. Sabol sabol at alderaan.gsfc.nasa.gov
Tue Nov 14 23:56:34 GMT 2006


Carlos Vicente wrote:
>> Using an iterator (AFAIK) does not load all the objects in memory.

Perrin replied:
> It loads all of their primary keys into memory, but doesn't bless those
> into objects until you fetch them from the iterator.  I guess it could
> go either way, since there's some overhead in the construct() call.
> Maybe a large result list would perform better with the iterator and a
> small one (e.g. single result) would be better without it.  You'd have
> to bench it to know for sure.

Certainly, if the result of the search() query is one or zero rows/objects,
then you are correct that first() loses by a slight margin due to the
additional method call, but I believe first() will win in every other case.
If the result of the search() query is 10 rows, for example, then the array
context will result in the instantiation of 10 CDBI objects (9 of which would
then be unused and DESTROY'ed) versus a single object instantiation with
first(). I believe the overhead with construct() is far more substantial than
you think. Again, I haven't personally benchmarked it, so I would be
interested in the findings of anyone who would care to do so.

Later,
Ed



More information about the ClassDBI mailing list