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
Reduce deque repeat execution when maxlen exist and size is not 1 #73820
Comments
There is a XXX in v3.5.0 shows that need to dealing with deque maxlen setting case in deque_repeat. Although there have common case for deque size 1 with maxlen, other size of deque with maxlen still using for-loop to extend the deque, without any detection. Adding this fast break will reduce the execution speed when repeat deque with maxlen. --- $ cat tests.py
from collections import deque
for _ in range(10:
d = deque(maxlen=100_000)
d.insert(0, 0)
d.insert(0, 10)
d * 10_000_000
$ time ./python_with_patch tests.py
$ time ./python tests.py |
Wouldn't be better to update the number of repeats before the loop rather than checking at every iteration? if (deque->maxlen >= 0 && n * size > deque->maxlen) |
Serhiy: yes, your advice is better than checking inside the loop. I have updated this to the commit, thanks! |
The code looks fine. Please change the comment to something like: /* Reduce the number of repetitions when maxlen would be exceeded */ |
Raymond: comment has changed, pushed on to GitHub. |
There is an opportunity of further optimisation. For example deque(range(100000), maxlen=100001) *= 2 copies 100000 elements while it is enough to copy just 1 element. But I don't know whether it is worth to optimise this. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: