Performance: Why querysets are lazy and powerful
HIGH IMPACT
This concept affects database query execution timing and page load speed by delaying data fetching until necessary.
users = User.objects.filter(is_active=True) for user in users: print(user.username)
all_users = list(User.objects.all()) for user in all_users: print(user.username)
| Pattern | Database Queries | Memory Usage | Blocking Time | Verdict |
|---|---|---|---|---|
| Eager loading with list() | 1 immediate query | High (loads all data) | Blocks rendering until done | [X] Bad |
| Lazy queryset iteration | Query runs on iteration | Lower (fetches as needed) | Non-blocking until data needed | [OK] Good |