Skip to content

Lazy Loading Faster than Eager loading? #2982

Open
@chrismeats

Description

@chrismeats

Summary of problem or feature request

I have a simple product hasMany variants relationship.
I can not figure out a slow performance issue.
If I eager load my variants relationship:
$query->with('variants');
Performance takes a serious hit and takes 3-4 seconds to load the page. Even though debug bar does not show any slow queries. and all queries execute in about 131ms

If I remove that eager load and just do lazy loading, page loads in 522ms even though there are 100 lazy loaded, essentially duplicate, queries! all queries execute in about 237ms

The slow down seems to come sometime during call to return $table->make(true);

I believe I have relevant code copied below. Thank you in advance for any help!

Code snippet of problem

$query = Product::with(['pc_variants'])->select(sprintf('%s.*', (new Product)->table));

$table = Datatables::of($query);
// --- Some other addColumn, editColumn, I have tried changing all my edit columns to just return 1 to ensure nothing there was slowing things down --- 
return $table->make(true); // This seems to be where the speed issue happens

System details

  • Operating System -- Mac Ventura 13.2 using Valet
  • PHP Version -- 8.1
  • Laravel Version -- 10.4
  • Laravel-Datatables Version -- 10.3.1

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions