#28828: Performance improvements for HttpRequest.build_absolute_uri()
--------------------------------------+------------------------------------
Reporter: gcbirzan | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by gcbirzan):
I've posted these in the PR comments, but, some benchmarks:
I ran this benchmark:
{{{timeit.timeit("request.build_absolute_uri(location='///foo/bar/')",
number=1000000, globals={'request': request})}}}
The results were:
* With my fix: 4.474267777055502
* With my fix but with bits.path![0] == '/': 4.34382488578558
* My shortcut but no cached property: 9.473239112645388 [this is to
simulate running this on different requests)
* No shortcut but with cached property: 12.506602805107832
*Original version: 17.600296460092068
There is a regression. Running without the cached property, to simulate
calling it in different requests, on a path with '.':
{{{timeit.timeit("request.build_absolute_uri(location='/foo/./bar/')",
number=1000000, globals={'request': request}))}}}
The results:
* My version, no cached property: 19.713809736073017
* Original version: 18.129451751708984
So, the extra checks do add some overhead, but it's for an uncommon case.
I don't have any evidence, obviously, but I'm fairly confident that the
overwhelming uses build_absolute_url() are with an absolute path that
doesn't have '.' or '..' in it and that the result is coming from reverse.
--
Ticket URL: <https://code.djangoproject.com/ticket/28828#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.f9069f869fd04c503634df75495771dd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.