[Django] #33937: Serialize is loading full objects when serializing m2m fields.

4 views
Skip to first unread message

Django

unread,
Aug 18, 2022, 9:14:00 AM8/18/22
to django-...@googlegroups.com
#33937: Serialize is loading full objects when serializing m2m fields.
-------------------------------------+-------------------------------------
Reporter: Gordon | Owner: nobody
Wrigley |
Type: | Status: new
Uncategorized |
Component: Core | Version: 4.0
(Serialization) |
Severity: Normal | Keywords: performance
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When not using natural keys, this function
https://github.com/django/django/blob/main/django/core/serializers/python.py#L64
loads the full object for every entry in the m2m, when it only actually
wants the pks which it could get off the m2m intermediate table without
even joining to the target table.

In my case the table we are m2m'ing to has files in it, so that's a
weighty fetch.
We are using django-reversion which stores a serialized version of each
save.
On the workload that flagged this up enabling reversion incurs a 300x
performance hit (from half a second to 2.5 minutes) and it's almost
entirely because of this.

--
Ticket URL: <https://code.djangoproject.com/ticket/33937>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages