Opened 6 years ago

Closed 5 years ago

#24720 closed Cleanup/optimization (fixed)

using middleware.common to append slashes causes extra overhead to all requests that do not end in a slash

Reported by: Jay Cox Owned by: nobody
Component: Core (Other) Version: master
Severity: Normal Keywords: optimization middleware common
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Checking if a url is valid is just as costly as fully resolving the url, so when the common middleware checks if it should append a slash it is fully doubling the url resolution overhead (which is about 5%) (this overhead only applies to urls that do not already end in a slash)

By deferring the checks until the process_response phase we can make sure that we only pay the price for urls that actually need a slash appended (that is to say would actually return a 404).

Pull request:
https://github.com/django/django/pull/4574

Change History (4)

comment:1 Changed 6 years ago by Tim Graham

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:2 Changed 6 years ago by Tim Graham

Patch needs improvement: unset

comment:3 Changed 6 years ago by Tim Graham

Needs documentation: set

comment:4 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 434d309e:

Fixed #24720 -- Avoided resolving URLs that don't end in a slash twice in CommonMiddleware.

This speeds up affected requests by about 5%.

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