Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32174 closed Cleanup/optimization (wontfix)

Error page can sometimes be very slow

Reported by: Anders Hovmöller Owned by:
Component: Error reporting Version: 3.1
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I hit a case in development today where the error page took over 20 seconds to render. After a bit of digging it happened for a few reasons:

  • fairly deep call chain (20)
  • the same arguments being passed down many levels
  • those arguments contained querysets
  • the querysets had reprs that accessed a related object

These things in combination resulted in almost 5000 database accesses.

I have a patch for this that can avoid this. It's pretty simple as the debug pretty printer goes through the entire stack in one for loop so it's easy to cache the sub-results.

Change History (2)

comment:1 by Carlton Gibson, 4 years ago

Resolution: wontfix
Status: newclosed

Hi Anders. Thanks for the report.

Slowness here is a symptom of chained ORM lookups, rather than the exception reporter per se. It's not something that we'd want to mask in general, because you want to notice it, so you can optimize your application.

If you do want to apply it yourself, your suggestion is the perfect case for the DEFAULT_EXCEPTION_REPORTER setting introduced in Django 3.1. Apply your cached pretty printer in a subclass and use it in your project.

I hope that makes sense.

comment:2 by Anders Hovmöller, 4 years ago

I disagree. Optimizing queries with prefetch or select related can be done later. You are saying that we should always apply optimizations first just in case a debug page is hit.

In any case, if you don't like the fix, would you be open to a change that would break apart the big function my PR modifies so that this change can be implemented locally without copy pasting that big function (risking compatibility problems, missed bug fixes etc)?

Note: See TracTickets for help on using tickets.
Back to Top