Skip to content

perf: avoid array.shift, use a linked list #7

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

Merged
merged 3 commits into from
May 2, 2024
Merged

perf: avoid array.shift, use a linked list #7

merged 3 commits into from
May 2, 2024

Conversation

Kikobeats
Copy link
Owner

@Kikobeats Kikobeats commented Apr 30, 2024

Instead of stacking promises into an array, it uses a linked list :kekwait:

The main advantage is that queue.shift hurts performance for large arrays cases because O(n), while a linked list keeps access time O(1) :doge-eyebrows:

Related: nodejs/node#42449 (comment)

instead of stack promises into an array, it uses a double linked list.

The main advantage is `queue.shift` hurts the performance when for big arrays O(n), while a double linked list keep access time constant O(1)
@Kikobeats Kikobeats changed the title feat: use DoublyLinkedList feat: use LinkedList Apr 30, 2024
Since the code is only adding elements to the end of the list and removing elements from the start of the list, that can be handled using a simple linked list.
@Kikobeats Kikobeats changed the title feat: use LinkedList perf: avoid array.shift, use a linked list Apr 30, 2024
@Kikobeats Kikobeats merged commit 0d0658f into master May 2, 2024
@Kikobeats Kikobeats deleted the queue branch May 2, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant