Refs #28459 -- Improved performance of select_related() when model is prefetched from its parent.
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 0b65bb56e8141..11976611509e7 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1665,21 +1665,10 @@ def __init__(self, klass_info, select, db):
             ]
             self.reorder_for_init = None
         else:
-            model_init_attnames = [
-                f.attname for f in klass_info['model']._meta.concrete_fields
-            ]
-            reorder_map = []
-            for idx in select_fields:
-                field = select[idx][0].target
-                init_pos = model_init_attnames.index(field.attname)
-                reorder_map.append((init_pos, field.attname, idx))
-            reorder_map.sort()
-            self.init_list = [v[1] for v in reorder_map]
-            pos_list = [row_pos for _, _, row_pos in reorder_map]
-
-            def reorder_for_init(row):
-                return [row[row_pos] for row_pos in pos_list]
-            self.reorder_for_init = reorder_for_init
+            attname_indexes = {select[idx][0].target.attname: idx for idx in select_fields}
+            model_init_attnames = (f.attname for f in klass_info['model']._meta.concrete_fields)
+            self.init_list = [attname for attname in model_init_attnames if attname in attname_indexes]
+            self.reorder_for_init = operator.itemgetter(*[attname_indexes[attname] for attname in self.init_list])
 
         self.model_cls = klass_info['model']
         self.pk_idx = self.init_list.index(self.model_cls._meta.pk.attname)

https://code.djangoproject.com/ticket/28459

Before:
```
In [2]: %timeit for x in Human.objects.select_related('person'): pass
196 ms ± 2.05 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
```

After:
```
In [2]: %timeit for x in Human.objects.select_related('person'): pass
186 ms ± 1.59 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
```