Latest Results
perf: replace RelationProxy.__getattribute__ with explicit count/clear (#1650)
Profile-driven removal of the per-attribute-access Python override on
RelationProxy. The previous __getattribute__ existed solely to redirect
two list-method names ("count", "clear") to the QuerysetProxy versions;
every other attribute access paid the cost of a Python-level
__getattribute__ call only to fall through to super.
cProfile (all_with_related, 40 000 row hydrations): __getattribute__
was 0.354 s tottime / 6.2 % of scenario time, with 420 000 calls. After
this change it is no longer in the top 25 by tottime — attribute access
goes through the C-level lookup path.
Replacement: define count() and clear() as async methods directly on
RelationProxy. They shadow list.count / list.clear by virtue of MRO and
delegate to queryset_proxy after self._initialize_queryset(). The
observable async semantics are unchanged: callers always did
``await proxy.count(...)`` / ``await proxy.clear(...)``; the previous
override returned a bound async method, the new methods are themselves
async — both produce the same coroutine.
Behavior unchanged: same signatures (distinct=True / keep_reversed=True
defaults), same delegation path, same QuerysetProxy initialization
trigger. 628 tests pass at 100 % coverage.
Benchmark deltas (median, pytest-benchmark, --warmup=on, 10+ rounds):
- test_get_all_with_related_models[10] -17.2 %
- test_get_all_with_related_models[20] -15.6 %
- test_get_all_with_related_models[40] -7.7 %
- test_get_all[250] -13.1 %
- test_get_all[500] -9.9 %
- test_get_all[1000] -6.4 %
- test_iterate[*] within noise
- single-row get_one / first I/O-dominated, ±15 % noise
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>check-optimisations-and-rs Latest Branches
-30%
check-optimisations-and-rs -28%
hk3dva:feature_add_schema_to_ormar_config -3%
SepehrBazyar:proxy_inheritance © 2026 CodSpeed Technology