Laravel Eloquent performance issue

eloquent, laravel, laravel-4

Solution

Finally I found out where the problem is. Actually, that issue is not really caused by Eloquent ORM but the view. That are what I did for fixed the problem

Eager loading: Since there are 4 relations in my view, so it cause N + 4 queries , I use the eager loading to fixed it. and use

Cache: I use remember() to cache results.

Cancel the Image checking: last things I did but most important, is to cancel the checking the Images in S3.

The page loading get a huge speed up. :)

Problem

when I use Eloquent to get data, and found out some performance issue In my case, I use laravel debugbar ( https://github.com/barryvdh/laravel-debugbar ) to collect the information I need. when I use ORM to get about 20 entries from my DB ``` $projects = Project::where('status', '=', 2)->get(); ``` it took about 24MB memory usage and 250ms but when I use the query builder as below ``` $projects = DB::table('Project')->where('status','=',2)->get(); ``` the database queries and the return data are almost the same, but query builder took only 11MB memory usage and 113ms to get the data. when the entries I need are about 200 entries, and even relate to other tables via ORM, it take almost 8000ms... and get the "Allowed memory size exhausted" error message very often.. So, I was wondering, in my condition, should I use the query builder and join other table? Or what should I do to speed up the Eloquent performance ?

Original source