#23623: ModelChoiceField generates unused temporary cache
-------------------------------------+-------------------------------------
     Reporter:  tchaumeny            |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |                  Version:  master
    Component:  Forms                |               Resolution:
     Severity:  Normal               |             Triage Stage:
     Keywords:  ModelChoiceField,    |  Unreviewed
  admin                              |      Needs documentation:  0
    Has patch:  1                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------
Description changed by tchaumeny:

Old description:

> There is a huge memory consumption when using some admin pages with big
> production datasets (see also https://groups.google.com/forum/#!topic
> /django-users/YYlLWyBH_go).
>
> I looked into the `ModelChoiceIterator` used to generate the choices for
> a `ModelChoiceField`, and noticed that an unused temporary queryset cache
> was generated due to the use of `.all()`, but unused (there is no
> variable pointing to the cloned queryset after the iteration).
>
> With the proposed PR, this cache is no longer generated. After applying
> the patch, I noticed that the maximum memory usage dropped from ~200MB to
> ~150MB for a model with about 30 000 instances.

New description:

 There is a huge memory consumption when using some admin pages with big
 production datasets (see also https://groups.google.com/forum/#!topic
 /django-users/YYlLWyBH_go).

 I looked into the `ModelChoiceIterator` used to generate the choices for a
 `ModelChoiceField`, and noticed that an unused temporary queryset cache
 was generated due to the use of `.all()` (there is no variable pointing to
 the cloned queryset after the iteration).

 With the proposed PR, this cache is no longer generated. After applying
 the patch, I noticed that the maximum memory usage dropped from ~200MB to
 ~150MB for a model with about 30 000 instances.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/23623#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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.76264376d531ecf5331ffffc375b5097%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to