The Fix
Changed `ClientRequest.connection_key` to be a `NamedTuple` to improve client performance.
Based on closed aio-libs/aiohttp issue #9364 · PR/commit linked
@@ -0,0 +1 @@
@@ -0,0 +1 @@
+Changed ``ClientRequest.connection_key`` to be a `NamedTuple` to improve client performance -- by :user:`bdraco`.
diff --git a/aiohttp/client_reqrep.py b/aiohttp/client_reqrep.py
index d9a7d1cd049..4da944d38dd 100644
Option A — Apply the official fix\nChanged `ClientRequest.connection_key` to be a `NamedTuple` to improve client performance.\nWhen NOT to use: This fix is not suitable if the application relies on the specific behavior of dataclass equality.\n\n
Why This Fix Works in Production
- Trigger: ConnectionKey hashing and equality has an unexpected impact on performance between master and 3.x
- Mechanism: Switching `ConnectionKey` from a dataclass to a NamedTuple improves performance by utilizing native code for hashing
Why This Breaks in Prod
- Switching `ConnectionKey` from a dataclass to a NamedTuple improves performance by utilizing native code for hashing
- Production symptom (often without a traceback): ConnectionKey hashing and equality has an unexpected impact on performance between master and 3.x
Proof / Evidence
- GitHub issue: #9364
- Fix PR: https://github.com/aio-libs/aiohttp/pull/9365
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.77
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“Looks like switching it to a NamedTuple will speed it up since the hashing can happen all in native code. Sadly its not cached though…”
“Performance regressed in https://github.com/aio-libs/aiohttp/pull/5284”
“connect with attrs !attrs_connect connect with namedtuple !namedtuple_connect”
Failure Signature (Search String)
- ConnectionKey hashing and equality has an unexpected impact on performance between master and 3.x
Copy-friendly signature
Failure Signature
-----------------
ConnectionKey hashing and equality has an unexpected impact on performance between master and 3.x
Error Message
Signature-only (no traceback captured)
Error Message
-------------
ConnectionKey hashing and equality has an unexpected impact on performance between master and 3.x
What Broke
Performance regression observed in connection management leading to slower client requests.
Why It Broke
Switching `ConnectionKey` from a dataclass to a NamedTuple improves performance by utilizing native code for hashing
Fix Options (Details)
Option A — Apply the official fix
Changed `ClientRequest.connection_key` to be a `NamedTuple` to improve client performance.
Fix reference: https://github.com/aio-libs/aiohttp/pull/9365
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not suitable if the application relies on the specific behavior of dataclass equality.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
- Pin production dependencies and upgrade only with a reproducible test that hits the failing path.
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.