﻿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
35102	Performance regression on Model.objects.count() between Django 4.2 and 5.0	Anthony Shaw	Simon Charette	"I was running the djangobench tool against the 4.2 and 5.0.1 tags (and main to verify) and noticed that some of the benchmarks had significant regressions.

The one I wanted to highlight is `query_count`. The other two with regressions were model creation and query_annotate.

`djangobench --control 4.2 --experiment 5.0.1 query_count -p profiles`

The profile for both versions shows that in v5, get_aggregation has an additional call to replace_expressions which spends a lot of time in the slow inspect module. In the profile reports I collected this accounts for the 30-40% performance regression on the count aggregation query. 

Performance regressions with new features are expected, but I wanted to raise this because the [ASV environment for Django](https://github.com/django/django-asv) seemed to have missed some of these regressions when all of the benchmarks suddenly ran faster. 

I've attached profiles for 4.2 and 5.0.1 which can be opened using something like snakeviz"	Cleanup/optimization	closed	Database layer (models, ORM)	5.0	Normal	fixed		Simon Charette	Ready for checkin	1	0	0	0	0	0
