Laravel chunk vs lazy vs cursor: lazy() Is as Slow as chunk()
I seeded a MySQL table with 1,000,000 orders and walked through every row with each of five Laravel methods for iterating a big query: chunk(), chunkById(), lazy(), lazyById() and cursor(). chunkById() finished in 21.9 seconds and lazyById() in 22.3, neither above 5.9 MB of PHP memory. chunk() and lazy() held just as little and took about six times as long. cursor(), which the Laravel docs offer as a way to "significantly reduce your application's memory consumption", finished behind both ById methods and held 100.4 MB.