~/talk

N+1 Problem in Django Rest Framework

Talkat PyCon AU 2023 · 2023-08-18..08-22· [python, web-performance]
links:none on file
slides:none on file

Shows that N+1 appears in Django Rest Framework both in view querysets and serializer fields and that using select_related and prefetch_related actually fixes it. Uses an author/book/tag example API, detects problems with nplusone and Django Debug Toolbar, and measures dramatic improvements — e.g. authors endpoint drops from about 197 queries to 7, books from ~53 to 5 — demonstrating the change is real and effective in practice.

AI-written summary · about

  1. 0:00Introduction
  2. 2:14Django Rest Framework
  3. 4:00N+1 problem in ORMs
  4. 8:18Example models
  5. 10:24N+1 in DRF views
  6. 12:58Serializer-level N+1
  7. 14:45Tools to detect N+1
  8. 18:42Solving N+1 with select_related
  9. 21:19Solving N+1 with prefetch_related
  10. 23:50DRF recommendations
  11. 24:54Performance impact
  12. 27:03References
  13. 28:09Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.