#35518: Avoid regex search for simple route patterns
-------------------------------------+-------------------------------------
     Reporter:  Jake Howard          |                    Owner:  Jake
         Type:                       |  Howard
  Cleanup/optimization               |                   Status:  new
    Component:  Core (URLs)          |                  Version:  5.2
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Jake Howard):

 * resolution:  needsinfo =>
 * status:  closed => new
 * version:  5.0 => 5.2

Comment:

 With some (slightly) less real-world examples, it's much clearer to see
 the benefit (running against `0f5dd0dff3049189a3fe71a62670b746543335d5`:

 {{{#!python
 import django
 from django.conf import settings
 from django.urls import resolve, path
 from django.http import HttpResponse

 settings.configure(
     ROOT_URLCONF=__name__
 )

 def main_view(request):
     return HttpResponse()

 urlpatterns = [
     path(f"foo{i}", main_view)
     for i in range(10_000)
 ]

 django.setup()
 }}}

 Before:

 {{{#!python
 In [2]: %timeit resolve("/foo9999")
 5.61 ms ± 103 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
 }}}


 After:

 {{{#!python
 In [1]: %timeit resolve("/foo9999")
 3.08 ms ± 52.3 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
 }}}

 A 45% improvement, with reduced variance, definitely feels worthwhile to
 me. It's _similar_ to #35252, but that optimises the `RoutePattern`
 definition (startup cost), whereas this affects runtime.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35518#comment:8>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070196900685e2-b8119458-f8ca-49ca-9310-9bf382f00c0e-000000%40eu-central-1.amazonses.com.

Reply via email to