The Fix
Significantly speeds up cookie filtering by adding a cache for morsel construction, reducing the need to create new Morsel objects for every request.
Based on closed aio-libs/aiohttp issue #9520 · PR/commit linked
@@ -0,0 +1 @@
@@ -0,0 +1 @@
+Significantly speed up filtering cookies -- by :user:`bdraco`.
diff --git a/aiohttp/cookiejar.py b/aiohttp/cookiejar.py
index 9b7f38d6685..85fd7716b56 100644
Option A — Apply the official fix\nSignificantly speeds up cookie filtering by adding a cache for morsel construction, reducing the need to create new Morsel objects for every request.\nWhen NOT to use: This fix is not applicable if using a different cookie management approach.\n\n
Why This Fix Works in Production
- Trigger: High latency observed due to repeated cookie creation during requests.
- Mechanism: Cookies are recreated for every request, causing performance issues
- If left unfixed, this can cause silent data inconsistencies that propagate (bad cache entries, incorrect downstream decisions).
Why This Breaks in Prod
- Shows up under Python 3.14 in real deployments (not just unit tests).
- Cookies are recreated for every request, causing performance issues
- Production symptom (often without a traceback): High latency observed due to repeated cookie creation during requests.
Proof / Evidence
- GitHub issue: #9520
- Fix PR: https://github.com/aio-libs/aiohttp/pull/9204
- Reproduced locally: No (not executed)
- Last verified: 2026-02-12
- Confidence: 0.80
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.82
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“If we don't find another solution by the time Python 3.14 is released, we can close this one”
“I think its unlikely we are going to be able to improve the performance without moving away from stdlib http.cookies”
“<img width="1233" alt="Screenshot 2024-10-17 at 9 55 31 PM" src="https://github.com/user-attachments/assets/ca7ffb41-ad96-494f-bca3-24451cae36b8">”
“I think we have to wait for https://github.com/python/cpython/pull/126157”
Failure Signature (Search String)
- High latency observed due to repeated cookie creation during requests.
Copy-friendly signature
Failure Signature
-----------------
High latency observed due to repeated cookie creation during requests.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
High latency observed due to repeated cookie creation during requests.
Environment
- Python: 3.14
What Broke
High latency observed due to repeated cookie creation during requests.
Why It Broke
Cookies are recreated for every request, causing performance issues
Fix Options (Details)
Option A — Apply the official fix
Significantly speeds up cookie filtering by adding a cache for morsel construction, reducing the need to create new Morsel objects for every request.
Fix reference: https://github.com/aio-libs/aiohttp/pull/9204
Last verified: 2026-02-12. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if using a different cookie management approach.
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.