Opened 6 months ago

Last modified 6 months ago

#35467 closed Cleanup/optimization

Prefer urlsplit() over urlparse() — at Initial Version

Reported by: Adam Johnson Owned by: nobody
Component: Utilities Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Many places in Django use [urlparse()](https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse), which supports the rarely-used “path parameter” syntax (not to be confused with query parameters). The urlsplit() function is similar but does not parse such path parameters, which makes it a bit faster.

I think most or all calls to urlparse() can be replaced with urlsplit(). This make make a small but measurable performance difference in common paths, such as in CsrfViewMiddleware or the test Client.

See more in this Anthony Sottile video: https://www.youtube.com/watch?v=ABJvdsIANds

Change History (0)

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