Opened 2 years ago

Last modified 2 years ago

#33937 closed Cleanup/optimization

Serialize is loading full objects when serializing m2m fields. — at Initial Version

Reported by: Gordon Wrigley Owned by: nobody
Component: Core (Serialization) Version: 4.0
Severity: Normal Keywords: performance
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top