﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33937	Optimize m2m serialization to avoid loading full model instances	Gordon Wrigley	mark evans	"When not using natural keys, the `handle_m2m_field` function([https://github.com/django/django/blob/aed60aee38215e293d6ec2f3c96ec55bb9a62fc2/django/core/serializers/python.py#L64 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."	Cleanup/optimization	closed	Core (Serialization)	4.0	Normal	fixed	performance		Ready for checkin	1	0	0	0	0	0
