Skip to content

Small speed up to cookiejar filter_cookies#8535

Merged
bdraco merged 3 commits intomasterfrom
cookie_paths
Jul 25, 2024
Merged

Small speed up to cookiejar filter_cookies#8535
bdraco merged 3 commits intomasterfrom
cookie_paths

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented Jul 25, 2024

What do these changes do?

Small speed up to cookiejar

Using str.format is ~16% faster than the lambda

followup to #7944 (comment). I was hoping to use join there but later realized str.format will take *args

Are there changes in behavior for the user?

no

Is it a substantial burden for the maintainers to support this?

no

benchmark

import timeit
import itertools

_FORMAT_PATH = "{0}/{1}".format

path = "lolonglonglonglonglonglongng/path/to/a/file"

print(
    timeit.timeit(
        'itertools.accumulate(path.split("/"), _FORMAT_PATH)', globals=globals()
    )
)


print(
    timeit.timeit(
        'itertools.accumulate(path.split("/"), lambda x, y: f"{x}/{y}")',
        globals=globals(),
    )
)

Using str.format is ~16% faster than the lambda
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jul 25, 2024
@codecov
Copy link
Copy Markdown

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.67%. Comparing base (549c95b) to head (2f19186).
Report is 915 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8535   +/-   ##
=======================================
  Coverage   97.67%   97.67%           
=======================================
  Files         107      107           
  Lines       33286    33288    +2     
  Branches     3918     3916    -2     
=======================================
+ Hits        32513    32515    +2     
  Misses        559      559           
  Partials      214      214           
Flag Coverage Δ
CI-GHA 97.59% <100.00%> (+<0.01%) ⬆️
OS-Linux 97.24% <100.00%> (+<0.01%) ⬆️
OS-Windows 95.68% <100.00%> (+<0.01%) ⬆️
OS-macOS 96.91% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.05% <100.00%> (-0.01%) ⬇️
Py-3.10.14 97.00% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.22% <100.00%> (+<0.01%) ⬆️
Py-3.12.4 97.36% <100.00%> (+<0.01%) ⬆️
Py-3.8.10 95.44% <100.00%> (+<0.01%) ⬆️
Py-3.8.18 96.89% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.04% <100.00%> (-0.01%) ⬇️
Py-3.9.19 96.99% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 96.56% <100.00%> (+<0.01%) ⬆️
VM-macos 96.91% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 97.24% <100.00%> (+<0.01%) ⬆️
VM-windows 95.68% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bdraco bdraco marked this pull request as ready for review July 25, 2024 01:58
@bdraco bdraco requested review from asvetlov and webknjaz as code owners July 25, 2024 01:59
@bdraco
Copy link
Copy Markdown
Member Author

bdraco commented Jul 25, 2024

thanks

@bdraco bdraco enabled auto-merge (squash) July 25, 2024 17:53
@bdraco bdraco merged commit 7108d64 into master Jul 25, 2024
@bdraco bdraco deleted the cookie_paths branch July 25, 2024 18:08
@patchback
Copy link
Copy Markdown
Contributor

patchback bot commented Jul 25, 2024

Backport to 3.10: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.10/7108d6469d20dd48919d312b2c654aef867ebe51/pr-8535

Backported as #8537

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jul 25, 2024
Co-authored-by: Sam Bull <[email protected]>
(cherry picked from commit 7108d64)
bdraco added a commit that referenced this pull request Jul 25, 2024
…_cookies (#8537)

**This is a backport of PR #8535 as merged into master
(7108d64).**


<!-- Thank you for your contribution! -->

## What do these changes do?
 
Small speed up to cookiejar

Using `str.format` is ~16% faster than the lambda

followup to
#7944 (comment). I
was hoping to use `join` there but later realized `str.format` will take
`*args`

## Are there changes in behavior for the user?

no
## Is it a substantial burden for the maintainers to support this?

no


benchmark
```python
import timeit
import itertools

_FORMAT_PATH = "{0}/{1}".format

path = "lolonglonglonglonglonglongng/path/to/a/file"

print(
    timeit.timeit(
        'itertools.accumulate(path.split("/"), _FORMAT_PATH)', globals=globals()
    )
)


print(
    timeit.timeit(
        'itertools.accumulate(path.split("/"), lambda x, y: f"{x}/{y}")',
        globals=globals(),
    )
)
```

Co-authored-by: J. Nick Koston <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants