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 天内回复