Repository navigation
Conversation
Foreign keys that are not selected used to build a separate pk-only related model for every row, e.g. 1000 Author placeholders for 1000 books by 50 authors. Rows pointing to the same pk from the same position now reuse one instance through the per-query row registry, the same way selected related models are shared since #1851. Models below a many-to-many relation stay scoped to their parent.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merging this PR will regress 2 benchmarks
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ |
test_min[500] |
5.3 ms | 7.2 ms | -26.77% |
| ❌ |
test_avg[250] |
6.4 ms | 7.3 ms | -12.66% |
| ⚡ |
test_get_all_with_related_models[40] |
30.6 ms | 22 ms | +38.84% |
| ⚡ |
test_get_all_with_related_models[20] |
18.4 ms | 14.4 ms | +28.06% |
| ⚡ |
test_duplicate_relation_paths[200] |
259.9 ms | 217.4 ms | +19.54% |
| ⚡ |
test_duplicate_relation_paths[100] |
135.3 ms | 114.1 ms | +18.61% |
| ⚡ |
test_duplicate_relation_paths[50] |
78.2 ms | 67.7 ms | +15.58% |
| ⚡ |
test_get_all_with_related_models[10] |
16.9 ms | 14.8 ms | +13.68% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing perf/share-pk-only-related (274c351) with master (67d8106)
Foreign keys that are not selected built a separate pk-only related model for every row (1000
Authorplaceholders for 1000 books by 50 authors), about half of the time of a plainall(). Rows pointing to the same pk from the same relation now reuse one instance through the per-query row registry from #1851; models below a many-to-many relation stay scoped to their parent.Book.objects.all()over 1000 rows is 1.8× faster (179ms → 98ms), reverseselect_related218ms → 149ms; serialized output is byte-identical to master.chapters[0].book is chapters[1].bookfor chapters of the same book, the placeholder's reverse relation lists all loaded rows, andawait chapter.book.load()fills it in for every row sharing it.