Performance: Why relationships model real data
MEDIUM IMPACT
This concept affects how efficiently the application queries and renders related data, impacting page load and interaction speed.
$users = User::with('profile')->get(); foreach ($users as $user) { echo $user->profile->bio; }
$users = User::all();
foreach ($users as $user) {
echo $user->profile->bio;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Lazy loading relationships (N+1 queries) | Minimal DOM nodes | Multiple reflows due to slow data | High paint cost due to delayed data | [X] Bad |
| Eager loading relationships | Minimal DOM nodes | Single reflow after data ready | Lower paint cost with fast data | [OK] Good |