Skip to content
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

[PR #7819/dfc3f899 backport][3.9] Skip filtering CookieJar when the jar is empty or all cookies have expired #7822

Commits on Nov 12, 2023

  1. Skip filtering CookieJar when the jar is empty or all cookies hav…

    …e expired (aio-libs#7819)
    
    The filtering itself and its preparation in `CookieJar.filter_cookies()`
    is expensive. Sometimes there are no cookies in the jar or all cookies
    have expired. Skip filtering and its preparation in this case.
    
    Because the empty check is much cheaper than `_do_expiration()`, I think
    it deserves to be duplicated before and after calling
    `_do_expiration()`.
    
    ```console
    $ python3.11 -m timeit -s 'from collections import defaultdict; d=defaultdict(foo="bar")' \
    > 'if not d: pass'
    50000000 loops, best of 5: 8.3 nsec per loop
    $ python3.11 -m timeit -s 'from collections import defaultdict; d=defaultdict()' \
    > 'if not d: pass'
    50000000 loops, best of 5: 8.74 nsec per loop
    $ python3.11 -m timeit -s 'from aiohttp import CookieJar; cj = CookieJar()' \
    > 'cj._do_expiration()'
    200000 loops, best of 5: 1.86 usec per loop
    ```
    
    (cherry picked from commit dfc3f89)
    Rongronggg9 committed Nov 12, 2023
    Configuration menu
    Copy the full SHA
    e6c071a View commit details
    Browse the repository at this point in the history