[arch-general] One more tiny patch that should bring a massive performance boost :D
Hello, During the recent libpng/libjpeg rebuilds, one thing that I noticed is that (big) Todo lists are really slow to load. Turns out that the current code is doing tons of simple queries (4 per package) which, although are quick to execute on the database server, take a considerable ammount of time to make. Thankfully, Django provides a mechanism to fetch all needed data in one go, which proved to be much faster during my testing. :) (If I should be sending these to a developer instead of this mailing list, please let me know.)
Use Django's select_related() on the TodolistPkg QuerySet to avoid making 4 database queries per package. This way we're making just one query, regardless of the number of packages in the Todo list. Local testing with 1000 entries in a Todo list show that the loading time has been reduced from 2675 ms to around 560 ms, while the number of queries has been cut down from 8005, to only 5. --- main/models.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/main/models.py b/main/models.py index f645804..1b08e1e 100644 --- a/main/models.py +++ b/main/models.py @@ -303,7 +303,7 @@ class Todolist(models.Model): @property def packages(self): - return TodolistPkg.objects.filter(list=self.id).order_by('pkg') + return TodolistPkg.objects.select_related().filter(list=self).order_by('pkg') @property def package_names(self): -- 1.6.6.1
On Mon, Jan 25, 2010 at 11:03 PM, Evangelos Foutras <foutrelis@gmail.com> wrote:
Use Django's select_related() on the TodolistPkg QuerySet to avoid making 4 database queries per package. This way we're making just one query, regardless of the number of packages in the Todo list.
Local testing with 1000 entries in a Todo list show that the loading time has been reduced from 2675 ms to around 560 ms, while the number of queries has been cut down from 8005, to only 5. --- main/models.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Thanks! This is a huge improvement. -Dan
On Mon, Jan 25, 2010 at 11:03 PM, Evangelos Foutras <foutrelis@gmail.com> wrote:
Hello,
During the recent libpng/libjpeg rebuilds, one thing that I noticed is that (big) Todo lists are really slow to load. Turns out that the current code is doing tons of simple queries (4 per package) which, although are quick to execute on the database server, take a considerable ammount of time to make.
Thankfully, Django provides a mechanism to fetch all needed data in one go, which proved to be much faster during my testing. :)
(If I should be sending these to a developer instead of this mailing list, please let me know.)
The ML is the right place for this, thanks a lot! -Dan
participants (2)
-
Dan McGee
-
Evangelos Foutras