﻿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
31732	Cache function signatures in django.utils.inspect.	Adam Johnson	Tim Park	"I found a bit of a performance regression in Django 2.1 and 2.2, gone in 3.0. There, `SQLCompiler.get_converters()` ran `func_supports_parameter()` for every field converter 

Unfortunately the information isn't cached and `inspect.signature()` isn't particularly fast.

Using py-spy on a client test suite, I found `func_supports_parameter()` taking 0.25% of the total run time. This isn't much absolutely, but it was reachable only through pathways using `Query.get_aggregation()` (2.1%) and `Query.get_count()` (0.63%). So from those paths, `func_supports_parameter()` took 0.25 / (2.1 + .63) = ~10% of the time to execute aggregates, for easily cached information.

Given that function objects are immutable, I think all the use of `inspect.signature` in `django.utils.inspect` could go through a wrapper that caches with a `WeakKeyDictionary` or `functools.lru_cache` to avoid re-inspecting the same signatures.

It doesn't look like there is any usage of those functions in hot paths in Django 3.0+ but it could be useful to have this protection for any future function argument deprecations."	Cleanup/optimization	closed	Utilities	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
