﻿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
16639	Optimize Model initialization by sending pre and post init signals only if there are listeners	Anssi Kääriäinen	nobody	"The attached patch implements an optimization to Model object initialization. The idea is to check if there are any listeners to signals. If not, then we can skip the sending and save time. The attached benchmark.tar.gz has some tests. Unpack and run python speedtester.py. See the file for details. 

The most interesting test is a loop of 10000 model initializations with a post and pre init signal listeners connected to a _different_ model. The result is that pre patch it takes 0.21 seconds to initialize objects, after patch only 0.07 seconds.

This situation is interesting because `GenericForeignKey` will attach to pre_init signal, and `ImageField` to post_init signal. So if you have both you will pay 0.14 seconds extra for every batch of 10000 objects created. That is true for all models in your project. After patch, you will pay the price only when there is somebody actually listening.

The patch is complete, expect that I don't know if support for .connect() without sender kwarg is needed. It is possible to support that case also, though a little more code is needed.

As a completely non-scientific data point, the test suite ran 2% faster after patch (and was passed)."	Cleanup/optimization	closed	Database layer (models, ORM)	1.3	Normal	wontfix		anssi.kaariainen@…	Design decision needed	1	0	0	1	0	0
