﻿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
37546	Avoid repeated list scans when sorting serialization dependencies	ChuaYuJien		"When `dumpdata --natural-foreign` runs on a project with many models, `django.core.serializers.sort_dependencies()` checks whether each dependency has already been sorted by scanning the growing output list. On a chain in which each model references the previous model, that makes the sorting work grow quadratically even when the input is already in dependency order.

The sorter already builds a set of the input models. Removing each model from that set when it is added to the output makes dependency membership checks constant time on average while preserving iteration order and the current cycle fallback.

On CPython 3.14.10 on Windows, the median sorting time for 1,000 linked Django models dropped from 9.562 ms to 2.297 ms. This benchmark measured dependency sorting alone. The reproduction script, regression test, and test results are in [https://github.com/django/django/pull/22360 draft PR #22360].

OpenAI Codex (GPT-6) helped identify the bottleneck, prepare the patch and test, run the benchmark, and draft this report."	Cleanup/optimization	new	Core (Serialization)	dev	Normal				Unreviewed	1	0	0	0	0	0
