CookieJar.add_cookie_header() is linear in the number of stored domains
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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分
- マージ済み PR(30日)
- 699
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信