[Django] #24397: Speed up model rendering with apps.ready = False

22 views
Skip to first unread message

Django

unread,
Feb 23, 2015, 5:05:03 PM2/23/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
--------------------------------------+--------------------
Reporter: knbk | Owner: knbk
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
Whenever a model is rendered, the cache of several values in `model._meta`
is cleared on each known model. This has a severe performance impact when
rendering large amounts of models.

When `apps.ready` is `False`, the cache of model meta options is not
cleared. This speeds up the initial rendering of the test suite
significantly. The cache can then be cleared manually when all models are
rendered, and `apps.ready` can be set back to`True`.

Results timing `django.test.runner.DiscoverRunner.setup_databases`:
{{{
apps.ready == True - 42 seconds
apps.ready == False - 16 seconds
}}}

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

Django

unread,
Feb 23, 2015, 5:09:47 PM2/23/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
-------------------------------------+-------------------------------------
Reporter: knbk | Owner: knbk
Type: | Status: new
Cleanup/optimization |
Component: Migrations | Version: master
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
-------------------------------------+-------------------------------------
Changes (by knbk):

* cc: knbk (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


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

Django

unread,
Feb 24, 2015, 9:03:14 AM2/24/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
--------------------------------------+------------------------------------

Reporter: knbk | Owner: knbk
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
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 timgraham):

* stage: Unreviewed => Accepted


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

Django

unread,
Mar 8, 2015, 9:54:21 AM3/8/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
--------------------------------------+------------------------------------
Reporter: knbk | Owner: knbk
Type: Cleanup/optimization | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

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 Markus Holtermann <info@…>):

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


Comment:

In [changeset:"888c9b6429a44824078a49fb1ebacf2e950cd887"]:
{{{
#!CommitTicketReference repository=""
revision="888c9b6429a44824078a49fb1ebacf2e950cd887"
Fixed #24397 -- Sped up rendering multiple model states.

Set apps.ready to False when rendering multiple models. This prevents
that the cache on Model._meta is expired on all models after each time a
single model is rendered. Prevented that Apps.clear_cache() refills the
cache on Apps.get_models(), so that the wrong value cannot be cached
when cloning a StateApps.
}}}

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

Django

unread,
Apr 6, 2015, 1:48:31 PM4/6/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
--------------------------------------+------------------------------------
Reporter: knbk | Owner: knbk
Type: Cleanup/optimization | Status: closed
Component: Migrations | Version: master

Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by knbk):

Additional PR: https://github.com/django/django/pull/4458

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

Django

unread,
Apr 6, 2015, 8:40:51 PM4/6/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
--------------------------------------+------------------------------------

Reporter: knbk | Owner: knbk
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
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 MarkusH):

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


Comment:

Reopen due to further improvements.

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

Django

unread,
Apr 10, 2015, 7:50:05 AM4/10/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
--------------------------------------+------------------------------------

Reporter: knbk | Owner: knbk
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


Comment:

Left some mostly cosmetic comments. Please advance to "Ready for Checkin"
after updating.

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

Django

unread,
Apr 17, 2015, 1:41:26 PM4/17/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
-------------------------------------+-------------------------------------
Reporter: knbk | Owner: knbk
Type: | Status: new
Cleanup/optimization |
Component: Migrations | Version: master
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 knbk):

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


Comment:

I'm not too sure what the error message should be changed to, so I'll
leave it as is.

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

Django

unread,
Apr 20, 2015, 2:42:49 PM4/20/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
-------------------------------------+-------------------------------------
Reporter: knbk | Owner: knbk
Type: | Status: new
Cleanup/optimization |
Component: Migrations | Version: master

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"039d7881b441c6b358a963d652ffa2eada3a8892" 039d7881]:
{{{
#!CommitTicketReference repository=""
revision="039d7881b441c6b358a963d652ffa2eada3a8892"
Refs #24397 -- Sped up model reloading in ProjectState.

Created bulk_update() context manager on StateApps. Sped up unregistering
models in reload_models() by using this context mananger.
}}}

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

Django

unread,
Apr 20, 2015, 2:46:27 PM4/20/15
to django-...@googlegroups.com
#24397: Speed up model rendering with apps.ready = False
-------------------------------------+-------------------------------------
Reporter: knbk | Owner: knbk
Type: | Status: closed
Cleanup/optimization |
Component: Migrations | Version: master
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 timgraham):

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


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

Reply all
Reply to author
Forward
0 new messages