CookieJar.add_cookie_header() is linear in the number of stored domains
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 54/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- backend, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 77.7k
- Fork
- 38.3k
- Merge trung bình
- 14 giờ 29 phút
- Pull request đã merge (30 ngày)
- 699
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
topic-socket type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python/cpython#160561 · 7 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
tests topic-profiling type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
python/cpython#160334 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
extension-modules type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Remove unused FVS_* macrosĐang mởinterpreter-core type-feature
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
python/cpython#160109 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
extension-modules type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python/cpython#160001 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python/cpython
Issue tương tự
-
request-theme
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 66/100
LizardByte/ThemerrDB#9575 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Author Page: noshin-nawalĐang mởauthor-page correction
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
acl-org/acl-anthology#10599 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
zilliztech/memsearch#818 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[FAQ] Commit ID for ProjectsCó thể đã có người làm @github-actions đã nhận hôm nay. Đang mởfaq-proposal
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
DataTalksClub/faq#503 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
README.zh-CN/ja/es still hard-code 501 test counts after README.md went count-freeCó thể đã có người làm @Aaqibhafeezkhan đã nhận hôm nay. Đang mởbeginner documentation good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
BistaDinesh03/critique#164 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày