Lots of images - speed improvement

I've been using lazyload plugin for some time in my small image gallery and it has been working like a charm for a while.
Until I added more than 500 images to one of folders. The result wasn't pleasing at all. Especially in firefox gallery was pretty sluggish.
After some analysis I found the main bottleneck - iterating over array of images. in $.grep and update.
After some coding I removed $.grep at all and replaced iteration in update() function with binary search algorithm. It runs much more smoothly but still could be improved (right now I don't know how). I commented added code quite well. Perhaps you could consider merging it to your project.