Opened 10 years ago

Last modified 9 years ago

#23623 closed Cleanup/optimization

ModelChoiceField generates unused temporary cache — at Version 1

Reported by: Thomas C Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords: ModelChoiceField, admin
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Thomas C)

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.

Change History (1)

comment:1 by Thomas C, 10 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top