CookieJar.add_cookie_header() is linear in the number of stored domains
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 54/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- python
- 領域
- backend, performance
研究方向
Start with http.cookiejar.CookieJar.add_cookie_header(), DefaultCookiePolicy.domain_return_ok(), and clear_expired_cookies() in the standard library, then run the test_http_cookiejar tests. The issue identifies three possible optimization paths, from caching request host parsing to changing domain lookup and expiry tracking. Done means the chosen change reduces work as the number of stored domains grows while the cookie jar tests continue to pass.
由索引模型根據 Issue 內容生成。
描述
Feature or enhancement
CookieJar.add_cookie_header() gets slower with every stored domain, even when only one cookie matches the request:
import timeit, urllib.request
from http.cookiejar import CookieJar, Cookie
def cookie(name, domain):
return Cookie(0, name, "v", None, False, domain, True, False, "/", True, False, None, True, None, None, {})
for n in (10, 100, 1000, 10000):
jar = CookieJar()
for i in range(n):
jar.set_cookie(cookie(f"c{i}", f"site{i}.example"))
req = urllib.request.Request("https://site0.example/")
t = min(timeit.repeat(lambda: jar.add_cookie_header(req), number=200, repeat=3)) / 200
print(f"{n:>6} domains: {t*1e6:8.1f} us")
10 domains: 37.9 us
100 domains: 320.8 us
1000 domains: 3086.9 us
10000 domains: 30450.6 us
Each call:
- Runs
DefaultCookiePolicy.domain_return_ok()for every stored domain, and each call re-parses the request URL viaeff_request_host(). - Runs
clear_expired_cookies(), which iterates every stored cookie.
Possible improvements, in increasing size:
- Compute
eff_request_host()once per request instead of once per domain. - With
DefaultCookiePolicy, look up only the domain keys that can match the request host (its dot-suffixes) instead of iterating all domains. - Track the earliest expiry in
set_cookie()and skip the sweep until it has passed.
HTTPX2 ships 2 and 3 as a CookieJar subclass, which passes test_http_cookiejar: https://github.com/pydantic/httpx2/pull/1285
I'm happy to send a PR.
- 主要語言
- Python
- 星號
- 77.7k
- 分支
- 38.3k
- 平均合併
- 14 小時 29 分鐘
- 30 天內合併 PR
- 699
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/cpython 的其他 Issue
-
topic-socket type-bug
難度 2/5 1-3 小時 新手友好度 72/100
python/cpython#160561 · 7 則留言 ·
維護者通常 1 天內回覆
-
tests topic-profiling type-bug
難度 2/5 1-3 小時 新手友好度 78/100
python/cpython#160334 · 1 則留言 ·
維護者通常 1 天內回覆
-
extension-modules type-bug
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
interpreter-core type-feature
難度 1/5 1 小時以內 新手友好度 78/100
python/cpython#160109 · 1 則留言 ·
維護者通常 1 天內回覆
-
extension-modules type-bug
難度 2/5 1-3 小時 新手友好度 72/100
python/cpython#160001 · 3 則留言 ·
維護者通常 1 天內回覆
相似的 Issue
-
request-theme
難度 1/5 1 小時以內 新手友好度 66/100
LizardByte/ThemerrDB#9575 ·
維護者通常 1 天內回覆
-
author-page correction
難度 2/5 1-3 小時 新手友好度 62/100
acl-org/acl-anthology#10599 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
zilliztech/memsearch#818 ·
維護者通常 1 天內回覆
-
[FAQ] Commit ID for Projects可能已有人在做 @github-actions 今天認領。 未關閉faq-proposal
難度 1/5 1 小時以內 新手友好度 84/100
DataTalksClub/faq#503 · 1 則留言 ·
維護者通常 2 天內回覆
-
README.zh-CN/ja/es still hard-code 501 test counts after README.md went count-free可能已有人在做 @Aaqibhafeezkhan 今天認領。 未關閉beginner documentation good first issue
難度 2/5 1-3 小時 新手友好度 75/100
BistaDinesh03/critique#164 · 1 則留言 ·
維護者通常 1 天內回覆