[Django] #33848: Migration StateApps.clone deepcopy too many objects

11 views
Skip to first unread message

Django

unread,
Jul 15, 2022, 6:43:57 PM7/15/22
to django-...@googlegroups.com
#33848: Migration StateApps.clone deepcopy too many objects
------------------------------------------------+------------------------
Reporter: Iuri de Silvio | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
`StateApps.clone` execute two slow deep copies. The first one copy all
models. The second one copy app configs, that include all apps and the
specific app models.

In my application, with ~250 models, this deepcopy is around 5% of
migration time. I was able to cleanup `StateApps` before copy, to not copy
all models and apps every operation again.

https://github.com/django/django/blob/d4c5d2b52c897ccc07f04482d3f42f976a79223c/django/db/migrations/state.py#L683

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

Django

unread,
Jul 15, 2022, 6:46:09 PM7/15/22
to django-...@googlegroups.com
#33848: Migration StateApps.clone deepcopy too many objects
-------------------------------------+-------------------------------------

Reporter: Iuri de Silvio | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Iuri de Silvio:

Old description:

> `StateApps.clone` execute two slow deep copies. The first one copy all
> models. The second one copy app configs, that include all apps and the
> specific app models.
>
> In my application, with ~250 models, this deepcopy is around 5% of
> migration time. I was able to cleanup `StateApps` before copy, to not
> copy all models and apps every operation again.
>
> https://github.com/django/django/blob/d4c5d2b52c897ccc07f04482d3f42f976a79223c/django/db/migrations/state.py#L683

New description:

`StateApps.clone` execute two slow deep copies. The first one copy all
models. The second one copy app configs, that include all apps and the
specific app models.

In my application, with ~250 models, this deepcopy is around 5% of
migration time. I was able to cleanup `StateApps` before copy, to not copy

all models and apps every operation again. After the optimization, it
takes less than 1% of migration time.

https://github.com/django/django/blob/d4c5d2b52c897ccc07f04482d3f42f976a79223c/django/db/migrations/state.py#L683

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33848#comment:1>

Django

unread,
Jul 16, 2022, 4:02:02 AM7/16/22
to django-...@googlegroups.com
#33848: Migration StateApps.clone deepcopy too many objects
-------------------------------------+-------------------------------------
Reporter: Iuri de Silvio | Owner: Iuri de
Type: | Silvio
Cleanup/optimization | Status: assigned

Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Simon Charette (added)
* owner: nobody => Iuri de Silvio
* status: new => assigned
* stage: Unreviewed => Accepted


Comment:

Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/33848#comment:2>

Django

unread,
Jul 16, 2022, 4:13:56 AM7/16/22
to django-...@googlegroups.com
#33848: Migration StateApps.clone deepcopy too many objects
-------------------------------------+-------------------------------------
Reporter: Iuri de Silvio | Owner: Iuri de
Type: | Silvio
Cleanup/optimization | Status: assigned
Component: Migrations | Version: 4.0
Severity: Normal | Resolution:
Keywords: | 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):

* stage: Accepted => Ready for checkin


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

Django

unread,
Jul 16, 2022, 10:59:58 AM7/16/22
to django-...@googlegroups.com
#33848: Migration StateApps.clone deepcopy too many objects
-------------------------------------+-------------------------------------
Reporter: Iuri de Silvio | Owner: Iuri de
Type: | Silvio
Cleanup/optimization | Status: closed
Component: Migrations | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: | 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:"f0fa2a3b49797f1e9830e2a0d2072119093b4452" f0fa2a3b]:
{{{
#!CommitTicketReference repository=""
revision="f0fa2a3b49797f1e9830e2a0d2072119093b4452"
Fixed #33848 -- Optimized StateApps.clone().
}}}

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

Reply all
Reply to author
Forward
0 new messages