-
-
Notifications
You must be signed in to change notification settings - Fork 831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slow performance when merging cookies #2875
Comments
Pulling in the stdlib
|
I think the biggest obstacle here is the fact that the Line 154 in fbe35ad
Users may want to access it in order to customize the cookie policy (which is set during initialization and accessed when adding a header). So a compatibility layer may be warranted, and it can get complex. Other than enforcing a cookie policy, the
It's |
There is a quite significant performance degradation when cookies are being used with requests.
httpx._client.BaseClient._merge_cookies
calls into the cookiejar here:When either
cookies
orself.cookies
is not None, thenhttpx._models.Cookies.__bool__
will call into a method calleddeepvalues
inhttp.cookiejar.CookieJar
by indirectly callinghttp.cookiejar.CookieJar.__iter__
.httpx._models.Cookies.__bool__
:http.cookiejar.CookieJar.__iter__
:Deepvalues is a significant performance hog because it does a lot of things recursively.
A suggested solution is to check
cookies
andself.cookies
for None instead of using__bool__
.I dropped a performance snapshot to illustrate the problem:
Here
deepvalues
takes up almost 17% of the CPU time.The text was updated successfully, but these errors were encountered: