﻿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
35285	Optimize ForeignObject._check_unique_target	Adam Johnson	Adam Johnson	"Continuing my project to optimize the system checks, I found some optimizations for `ForeignObject._check_unique_target`, which I found to take ~6% of the total runtime for checks.

Most of this function’s runtime was spent creating the set-of-frozensets describing all unique constraints on the target model. But this set is not needed to determine success in the most typical cases, where a primary key or other single unique field is targeted.

To optimize, we can check for a single unique field first. This essentially means restoring the “fast path” replaced in #25535 / 80dac8c33e7f6f22577e4346f44e4c5ee89b648c with a broad general algorithm to cover unique constraints.

Before optimization stats:

Profiling running checks 100 times, 20,800 calls took 180ms, or ~6% of the total runtime.

After optimization:

29ms or ~1% of the total runtime."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
