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?
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With