#30563: Optimize django.forms.widgets.Media.__add__.
--------------------------------------+------------------------------------
     Reporter:  didorothy             |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Forms                 |                  Version:  master
     Severity:  Normal                |               Resolution:
     Keywords:  media                 |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Matthias Kestenholz):

 I wonder how many distinct lists of assets you have? In the example above
 you're merging the same list 100'000 times.

 When calling `merge` earlier than at the end it will always be
 (relatively) easy to construct a failing test case.

 Maybe deduplicating the list of assets to merge would help? Something like
 (completely untested)

 {{{
 ~/Projects/django$ git diff
 diff --git a/django/forms/widgets.py b/django/forms/widgets.py
 index c8ec3c35d5..248c29b4c1 100644
 --- a/django/forms/widgets.py
 +++ b/django/forms/widgets.py
 @@ -124,7 +124,7 @@ class Media:
          """
          dependency_graph = defaultdict(set)
          all_items = OrderedSet()
 -        for list_ in filter(None, lists):
 +        for list_ in OrderedSet(filter(None, lists)):
              head = list_[0]
              # The first items depend on nothing but have to be part of
 the
              # dependency graph to be included in the result.
 ~/Projects/django$
 }}}

 It might be better for the memory usage to deduplicate earlier (inside
 `Media.__add__` maybe).

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30563#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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.860b693d7da2d272bb998e282173318a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to