#36520: Performance Regression in parse_header_params
---------------------------------+------------------------------------
     Reporter:  David Smith      |                    Owner:  (none)
         Type:  Bug              |                   Status:  new
    Component:  HTTP handling    |                  Version:  dev
     Severity:  Release blocker  |               Resolution:
     Keywords:                   |             Triage Stage:  Accepted
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+------------------------------------
Comment (by David Smith):

 Yes, `get_params()` seems to be where most of the time is being spent.

 The 5x claim I made above is just looking at this function. Other things
 are happening in the ASV benchmarks, so the impact shown there is much
 smaller. Maybe that's a good reason to suggest that even though this
 function is much slower, it is small in the overall request/response
 cycle. However, I think that as this is called with every request even
 small gains are worth having.

 I have done a bit more work on this. We could optimise for content types
 that do not include parameters and avoid a lot of the work in this case.
 Something like this:

 I'm rather unsure how common parameters are. Some evidence would be useful
 to avoid optimising for the wrong thing.

 {{{

 diff --git a/django/utils/http.py b/django/utils/http.py
 index 1c7aec7141..111740cd02 100644
 --- a/django/utils/http.py
 +++ b/django/utils/http.py
 @@ -326,6 +326,10 @@ def parse_header_parameters(line,
 max_length=MAX_HEADER_LENGTH):
      if max_length is not None and line and len(line) > max_length:
          raise ValueError("Unable to parse header parameters (value too
 long).")

 +    if line and ";" not in line:
 +        # No parameters, just return the content type.
 +        return line.strip().lower(), {}
 +
      m = Message()
      m["content-type"] = line
      params = m.get_params()

 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36520#comment:2>
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/010701983c2832ec-0383fb66-4956-4c68-afb6-42d66917ce84-000000%40eu-central-1.amazonses.com.

Reply via email to