-
Notifications
You must be signed in to change notification settings - Fork 2
4-unrolled.js has unnecessary allocations #1
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
Comments
you won't believe it, I'm preparing such an example, just now, but but with one spare buffer, not a pool |
@vird moreover, we can use list of nodes as a pool, to avoid creating new machinery for it, so list will have 3 refs: tail, current, head. We will enqueue to current. After removing from tail will move to head. |
Object pool with linked list storage instead of array for me is more or less equivalent by effect, so I'm still calling it object pool. |
@vird See new implementations: 5, 6, 7 |
7-current.js
Same with nodeSize
all 5, 6, 7
Similar for QueueNode (most fields can be marked as private)
typical way to display list is
|
In all listed implementations we call reset only when length already === 0 |
QueueNode and Pool are internal classes in this implementation, we use private fields just for external interface of Queue. But in |
QueueNode is big enough 2048 by default, in most cases we do not need pool, just single spare buffer of 2048 elements is ok, it is subject of performance tests to detect best solution for certain cases |
@vird gpt just can't understand combined logic of queue and pool, we use #tail as a pool |
|
My results differ a lot
node v22.13.1
|
And I disagree about benchmark methodology, so I write my own
|
https://github.com/vird/Queue/tree/feat/inlined node v22.13.1
new test
|
FixedCircularBuffer allocates once.
UnrolledQueue allocates each time QueueNode overflows
Object pool for QueueNode is needed to reduce allocations
The text was updated successfully, but these errors were encountered: