Re: [Django] #33937: Optimize m2m serialization to avoid loading full model instances

17 views
Skip to first unread message

Django

unread,
Aug 18, 2022, 12:10:35 PM8/18/22
to django-...@googlegroups.com
#33937: Optimize m2m serialization to avoid loading full model instances
--------------------------------------+------------------------------------
Reporter: Gordon Wrigley | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: 4.0
Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Mariusz Felisiak):

> 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.

What about natural keys? They can contain any combination of fields (also
non-unique in general).

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

Django

unread,
Aug 18, 2022, 1:21:43 PM8/18/22
to django-...@googlegroups.com
#33937: Optimize m2m serialization to avoid loading full model instances
--------------------------------------+------------------------------------
Reporter: Gordon Wrigley | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Serialization) | Version: 4.0
Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by Gordon Wrigley):

Replying to [comment:2 Mariusz Felisiak]:


> > 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.
>
> What about natural keys? They can contain any combination of fields
(also non-unique in general).

It loads the whole objects for the natural key case as well, but I don't
know if that is avoidable, whereas the PK case seems like it should be
easily avoidable (and is also the one I care about :P )

--
Ticket URL: <https://code.djangoproject.com/ticket/33937#comment:3>

Django

unread,
Sep 3, 2022, 9:52:53 AM9/3/22
to django-...@googlegroups.com
#33937: Optimize m2m serialization to avoid loading full model instances
-------------------------------------+-------------------------------------
Reporter: Gordon Wrigley | Owner:
Type: | marknotfound
Cleanup/optimization | Status: assigned
Component: Core | Version: 4.0
(Serialization) |

Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by marknotfound):

* owner: nobody => marknotfound
* status: new => assigned


Comment:

Going to take this on as my first Django ticket. Should have a patch
shortly.

--
Ticket URL: <https://code.djangoproject.com/ticket/33937#comment:4>

Django

unread,
Sep 4, 2022, 6:06:10 PM9/4/22
to django-...@googlegroups.com
#33937: Optimize m2m serialization to avoid loading full model instances
-------------------------------------+-------------------------------------
Reporter: Gordon Wrigley | Owner: mark
Type: | evans

Cleanup/optimization | Status: assigned
Component: Core | Version: 4.0
(Serialization) |
Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by mark evans):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33937#comment:5>

Django

unread,
Sep 4, 2022, 6:06:53 PM9/4/22
to django-...@googlegroups.com
#33937: Optimize m2m serialization to avoid loading full model instances
-------------------------------------+-------------------------------------
Reporter: Gordon Wrigley | Owner: mark
Type: | evans
Cleanup/optimization | Status: assigned
Component: Core | Version: 4.0
(Serialization) |
Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by mark evans):

I've submitted a patch here: https://github.com/django/django/pull/16028

--
Ticket URL: <https://code.djangoproject.com/ticket/33937#comment:6>

Django

unread,
Sep 5, 2022, 12:52:03 AM9/5/22
to django-...@googlegroups.com
#33937: Optimize m2m serialization to avoid loading full model instances
-------------------------------------+-------------------------------------
Reporter: Gordon Wrigley | Owner: mark
Type: | evans
Cleanup/optimization | Status: assigned
Component: Core | Version: 4.0
(Serialization) |
Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33937#comment:7>

Django

unread,
Sep 5, 2022, 2:25:06 PM9/5/22
to django-...@googlegroups.com
#33937: Optimize m2m serialization to avoid loading full model instances
-------------------------------------+-------------------------------------
Reporter: Gordon Wrigley | Owner: mark
Type: | evans
Cleanup/optimization | Status: assigned
Component: Core | Version: 4.0
(Serialization) |
Severity: Normal | Resolution:
Keywords: performance | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33937#comment:8>

Django

unread,
Sep 5, 2022, 2:51:30 PM9/5/22
to django-...@googlegroups.com
#33937: Optimize m2m serialization to avoid loading full model instances
-------------------------------------+-------------------------------------
Reporter: Gordon Wrigley | Owner: mark
Type: | evans
Cleanup/optimization | Status: closed

Component: Core | Version: 4.0
(Serialization) |
Severity: Normal | Resolution: fixed

Keywords: performance | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"19e0587ee596debf77540d6a08ccb6507e60b6a7" 19e0587e]:
{{{
#!CommitTicketReference repository=""
revision="19e0587ee596debf77540d6a08ccb6507e60b6a7"
Fixed #33937 -- Optimized serialization of related m2m fields without
natural keys.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33937#comment:9>

Reply all
Reply to author
Forward
0 new messages