Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Lazy Load Iterator

I have an iterator class that loops over an array of objects and lazily loads from the database when it needs to (when it's not loaded into memory). Problem is this is iterating around 200,000 times and I found out from here: http://www.garfieldtech.com/blog/magic-benchmarks that the iterator interface is incredibly slow.

Would anyone know of a good way to lazy load without using an iterator interface?

like image 217
Louis Avatar asked Jan 04 '10 06:01

Louis


1 Answers

You could use a plain old for loop.

The iterator interface might be slow, but when doing 200.000 DB queries, chances are pretty good your bottleneck is not the iterator. I'd suggest to profile your code to see if it is really in need of optimization at this position.

Premature Optimizatizion is the root of all evil :)

like image 161
Gordon Avatar answered Oct 14 '22 04:10

Gordon