#36242: NodeList render overhead with huge templates
-------------------------------------+-------------------------------------
     Reporter:  Michal Čihař         |                    Owner:  (none)
         Type:                       |                   Status:  closed
  Cleanup/optimization               |
    Component:  Uncategorized        |                  Version:  5.1
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Michal Čihař):

 This all made me look into the implementation, and the list comprehension
 seems like the best approach in this case. It calls `PySequence_Fast`
 which converts iterable into a list if it is not a list or a tuple.
 Creating a list using comprehension should be faster than creating a
 generator and then converting it to the list, but it most likely depends
 on the CPU cache size and this is the corner case I observe (the strings
 fill the CPU cache in my case).

 Additionally, there is a fast path for same width Unicode strings
 (separator + all items), so pure ASCII is:

 {{{
 (py3.14) nijel@lobsang:/tmp$ python -m timeit -n 1000 '"".join(["x" * 5000
 for n in range(1000)])'
 1000 loops, best of 5: 4.34 msec per loop
 (py3.14) nijel@lobsang:/tmp$ python -m timeit -n 1000 '"".join("x" * 5000
 for n in range(1000))'
 1000 loops, best of 5: 772 usec per loop
 }}}

 But once you mix Unicode into that:

 {{{
 (py3.14) nijel@lobsang:/tmp$ python -m timeit -n 1000 '"".join(["š" * 5000
 for n in range(1000)])'
 1000 loops, best of 5: 10.5 msec per loop
 (py3.14) nijel@lobsang:/tmp$ python -m timeit -n 1000 '"".join("š" * 5000
 for n in range(1000))'
 1000 loops, best of 5: 10.4 msec per loop
 }}}

 And now any difference is gone. So, indeed, this is not a way to optimize.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36242#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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019584405d62-8c5a284a-737a-487e-909e-ff8bf4d49762-000000%40eu-central-1.amazonses.com.

Reply via email to