Opened 21 months ago

Last modified 21 months ago

#33937 closed Cleanup/optimization

Optimize m2m serialization to avoid loading full model instances — at Version 1

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 (last modified by Adam Johnson)

When not using natural keys, the handle_m2m_field function(source) loads the full object for every entry in the m2m model, when it only needs the pks. The pk's can even be obtained from the m2m intermediate table, without joining 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 (1)

comment:1 by Adam Johnson, 21 months ago

Description: modified (diff)
Summary: Serialize is loading full objects when serializing m2m fields.Optimize m2m serialization to avoid loading full model instances
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization
Note: See TracTickets for help on using tickets.
Back to Top