#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 |
-------------------------------------+-------------------------------------
Changes (by tchaumeny):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
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 a temporary queryset cache was
> generated.
>
> 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()`, 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.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23623#comment:1>
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.7fe0a5e79be35e7a09b50ff84ec311ef%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.