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

TaskSet's _task_queue should be a collections.deque? #2653

Closed
2 tasks done
bakhtos opened this issue Mar 26, 2024 · 2 comments
Closed
2 tasks done

TaskSet's _task_queue should be a collections.deque? #2653

bakhtos opened this issue Mar 26, 2024 · 2 comments

Comments

@bakhtos
Copy link
Contributor

bakhtos commented Mar 26, 2024

Prerequisites

Description

While examining the source code to prepare the PR for #2651, I noticed that the TaskSet attribute _task_queue is a list, however insert/remove operations are performed both at the beginning and at the end.

Python has a dedicated deque for such operations, in particular:

Deques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.
Though list objects support similar operations, they are optimized for fast fixed-length operations and incur O(n) memory movement costs for pop(0) and insert(0, v) operations which change both the size and position of the underlying data representation.

Should this be changed?

I could implement the change in the same pull request.

@cyberw
Copy link
Collaborator

cyberw commented Mar 26, 2024

That makes a ton of sense to me. PR:s welcome!

@cyberw
Copy link
Collaborator

cyberw commented May 7, 2024

Fixed in #2698

@cyberw cyberw closed this as completed May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants