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

queue.SimpleQueue() uses just a list in it's C implementation. deque wouuld be much faster. #120926

Closed
socketpair opened this issue Jun 23, 2024 · 5 comments
Labels
pending The issue will be closed if no feedback is provided performance Performance or resource usage type-feature A feature request or enhancement

Comments

@socketpair
Copy link
Contributor

socketpair commented Jun 23, 2024

Feature or enhancement

Proposal:

deque is much faster for operations like appendleft() + popright() than just a list. C implementation uses list (array) instead of linked-list (deque)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

@socketpair socketpair added the type-feature A feature request or enhancement label Jun 23, 2024
@Eclips4 Eclips4 added the performance Performance or resource usage label Jun 23, 2024
@rhettinger
Copy link
Contributor

There might be a win here, but I think the current code is hard to beat.

@socketpair
Copy link
Contributor Author

@rhettinger, yes, you are right, someone should do a benchmark. Theoretically, a linked list should be faster.

Circular buffer would be even better, but requires the queue to be bound to a specific size.

@erlend-aasland
Copy link
Contributor

It's not worth it to keep an issue open for theoretical speedups; I suggest you try it out on your fork, benchmark it, and if there is a substantial performance gain, come back and create an issue.

@erlend-aasland erlend-aasland added the pending The issue will be closed if no feedback is provided label Jun 23, 2024
@rhettinger
Copy link
Contributor

The existing code implements a circular buffer on top of a C array. Unlike a Python list, the pop(0) step is O(1). It looks like the only possible win would be in eliminating the resize steps when the ring buffer size doubles or halves. Even then, the memcpy() step is very fast. And if the buffer reaches a steady state size, there is almost zero overhead.

@socketpair
Copy link
Contributor Author

Okay, @rhettinger if it uses ring buffer already, I think, I can do nothing in order to make it better. So, closing the issue.

@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending The issue will be closed if no feedback is provided performance Performance or resource usage type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants