-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Remove _next_expiration field from CookieJar #7790
Comments
Indeed this _next_expiration field was used to perform fast removal of expired cookies, but a posterior commits deleted the line of code that was using it: Line 87 in d65f5cb
Since that line of code has been deleted, _next_expiration is useless now (and the cleaning of cookies is slower as it doesn't use it to cut short the clear process). The commit that deleted this line of code is As an alternative to removing _next_expiration entirely, this line of code could be reintroduced. However this is more difficult now, as this commit made the _do_expiration code to be removed, and call instead the clear method, which now serves additional needs, like allowing custom selection of cookies to be cleared through a callback function. To revert this, the old _do_expiration code shall be reinstated, instead of delegating the work to the clear method. More largely, frequent execution paths (_do_expiration is called very often across the entire API) shall have simple code benefiting from shortcuts (like the _next_expiration field to determine if the expiration process can be skipped) and rare paths (like a clear operation with a custom selection function) could be isolated into dedicated code. |
Ideally the In Home Assistant we see a lot of time spent in |
Same here - I use aiohttp for a large-scale crawler. It works wonder, excepted the time it spends processing the cookie jar. The code seems complex and, potentially, not optimized for the frequent case (expiring cookies before selecting the set of active cookies to send to a website) but for rare cases (clearing cookies based on a custom logic). |
How many cookies were in the jar? I have several thousands (across a couple hundred domains) |
I don't have a good way to inspect that as its from a live running instance, but I can clearly say no where near that many. I'd ballpark it to be 50-100 at most. I expect for your use case you probably spend the bulk of the request time in the cookie jar. |
Yep that's what I see. The cookie jar is not scalable, specifically due to the expiration logic. |
Sounds like reintroducing it is the correct approach then. |
In fact the entire logic could be switched in favor of a time-ordered expiry queue. That way, there is never any need to loop over every cookie. Only the ones in front of the queue (the ones due to expire soon) need to be checked. The loop is exited as soon as the next iterated cookie from that queue is not expired yet. The |
Well, feel free to come up with a proposal, if it's clearly better without too much complexity, then we can merge it. |
Sounds great, I will wait for #7777 to be merged and then, depending on if it resolved this issue or not and the new capabilities it offers, make a proposal. |
It doesn't change the expirations, but will reduce the number of cookies being looked at in filter_cookies(). Mainly just want to make sure you don't end up with a load of merge conflicts. |
I understand, I will find the best path. |
In case its help to test against. Below is a basic benchmark (can likely be improved)
|
This is a great benchmark - will use it and publish sample measures for future reference |
PR is merged now, so feel free to propose further changes. |
@dmoklaf Still planning to work on this? |
I think in september |
Is your feature request related to a problem?
The _next_expiration field seems unused in CookieJar. It is only written to and never read in any part of aiohttp:
aiohttp/aiohttp/cookiejar.py
Line 84 in a57dc31
Describe the solution you'd like
Remove the field if it's useless
Describe alternatives you've considered
Maybe that it was intended for something that was never completely coded (e.g.,fast removal of expired cookies).
Related component
Client
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: