#33865: Optimize django.core.handlers.wsgi.LimitedStream
-------------------------------------+-------------------------------------
     Reporter:  Nick Pope            |                    Owner:  Nick Pope
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  HTTP handling        |                  Version:  dev
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  wsgi,                |             Triage Stage:  Ready for
  limitedstream, performance         |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"b47f2f5b907732d80b164f1f361ae39da94a3fa6" b47f2f5]:
 {{{
 #!CommitTicketReference repository=""
 revision="b47f2f5b907732d80b164f1f361ae39da94a3fa6"
 Fixed #33865 -- Optimized LimitedStream wrapper.

 The current implementation of LimitedStream is slow because .read()
 performs an extra copy into a buffer and .readline() performs two
 extra copies. The stream being wrapped is already typically a BytesIO
 object so this is unnecessary.

 This implementation has largely been untouched for 12 years and,
 inspired by a simpler implementation in werkzeug, it was possible to
 achieve the following performance improvement:

 LimitedStream.read() (single line):
   Mean +- std dev: [bench_limitedstream-main] 286 ns +- 6 ns
   -> [bench_limitedstream-patch] 227 ns +- 6 ns: 1.26x faster
 LimitedStream.readline() (single line):
   Mean +- std dev: [bench_limitedstream-main] 507 ns +- 11 ns
   -> [bench_limitedstream-patch] 232 ns +- 8 ns: 2.18x faster
 LimitedStream.read(8192) (single line):
   Mean +- std dev: [bench_limitedstream-main] 360 ns +- 8 ns
   -> [bench_limitedstream-patch] 297 ns +- 6 ns: 1.21x faster
 LimitedStream.readline(8192) (single line):
   Mean +- std dev: [bench_limitedstream-main] 602 ns +- 10 ns
   -> [bench_limitedstream-patch] 305 ns +- 10 ns: 1.98x faster
 LimitedStream.read() (multiple lines):
   Mean +- std dev: [bench_limitedstream-main] 290 ns +- 5 ns
   -> [bench_limitedstream-patch] 236 ns +- 6 ns: 1.23x faster
 LimitedStream.readline() (multiple lines):
   Mean +- std dev: [bench_limitedstream-main] 517 ns +- 19 ns
   -> [bench_limitedstream-patch] 239 ns +- 7 ns: 2.16x faster
 LimitedStream.read(8192) (multiple lines):
   Mean +- std dev: [bench_limitedstream-main] 363 ns +- 8 ns
   -> [bench_limitedstream-patch] 311 ns +- 11 ns: 1.17x faster
 LimitedStream.readline(8192) (multiple lines):
   Mean +- std dev: [bench_limitedstream-main] 601 ns +- 12 ns
   -> [bench_limitedstream-patch] 308 ns +- 7 ns: 1.95x faster

 Geometric mean: 1.59x faster
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33865#comment:14>
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 on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018583925496-c07c3e0e-efc7-483d-9d83-2860b4e39c20-000000%40eu-central-1.amazonses.com.

Reply via email to