-
Notifications
You must be signed in to change notification settings - Fork 120
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
chore(perf): Revert commit to bring back up to 20% perf #574
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,9 +63,19 @@ test('remove not queued task should not lead to errors', async ({ equal }) => { | |
}); | ||
|
||
test('removing elements from intermediate CircularBuffer should not lead to issues', async ({ equal, same }) => { | ||
/* | ||
The test intends to check following scenario: | ||
1) We fill the queue with 3 full circular buffers amount of items. | ||
2) Empty the middle circular buffer with remove(). | ||
3) This should lead to the removal of the middle buffer from the queue: | ||
- Before emptying: tail buffer -> middle buffer -> head buffer. | ||
- After emptying: tail buffer -> head buffer. | ||
*/ | ||
|
||
const queue = new FixedQueue(); | ||
|
||
const batchSize = 2048; | ||
// size of single circular buffer | ||
const batchSize = 2047; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it fails with 2048? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general it doesn't fail but it should match the batch size due to test's intensions.
My initial There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, now is clear; maybe add that to the description of the test can help understand why are we doing that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although I added the description I must admit that the test is actually insufficient/fragile due to lack of internal checks. const queue = new FixedQueue()
let buffer = queue.tail
let count = 0
while (buffer !== null) {
count++
buffer = buffer.next
}
console.log(`The queue has ${count} buffers`) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, I'd not recommend to alter the internals just for testing; I've always advocated for testing the outcome rather than expectations. At the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I completely agree that it's not the right way. I just worry about further consequences due to the lack of clarity. |
||
|
||
const firstBatch = Array.from({ length: batchSize }, () => new QueueTask()); | ||
const secondBatch = Array.from({ length: batchSize }, () => new QueueTask()); | ||
|
@@ -94,9 +104,18 @@ test('removing elements from intermediate CircularBuffer should not lead to issu | |
}); | ||
|
||
test('removing elements from first CircularBuffer should not lead to issues', async ({ equal, same }) => { | ||
/* | ||
The test intends to check following scenario: | ||
1) We fill the queue with 3 full circular buffers amount of items. | ||
2) Empty the first circular buffer with remove(). | ||
3) This should lead to the removal of the tail buffer from the queue: | ||
- Before emptying: tail buffer -> middle buffer -> head buffer. | ||
- After emptying: tail buffer (previously middle) -> head buffer. | ||
*/ | ||
const queue = new FixedQueue(); | ||
|
||
const batchSize = 2048; | ||
// size of single circular buffer | ||
const batchSize = 2047; | ||
|
||
const firstBatch = Array.from({ length: batchSize }, () => new QueueTask()); | ||
const secondBatch = Array.from({ length: batchSize }, () => new QueueTask()); | ||
|
@@ -125,9 +144,18 @@ test('removing elements from first CircularBuffer should not lead to issues', as | |
}); | ||
|
||
test('removing elements from last CircularBuffer should not lead to issues', async ({ equal, same }) => { | ||
/* | ||
The test intends to check following scenario: | ||
1) We fill the queue with 3 full circular buffers amount of items. | ||
2) Empty the last circular buffer with remove(). | ||
3) This should lead to the removal of the head buffer from the queue: | ||
- Before emptying: tail buffer -> middle buffer -> head buffer. | ||
- After emptying: tail buffer -> head buffer (previously middle). | ||
*/ | ||
const queue = new FixedQueue(); | ||
|
||
const batchSize = 2048; | ||
// size of single circular buffer | ||
const batchSize = 2047; | ||
|
||
const firstBatch = Array.from({ length: batchSize }, () => new QueueTask()); | ||
const secondBatch = Array.from({ length: batchSize }, () => new QueueTask()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do benchmarks with payloads twice or three times its size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to push something bigger than integers or just more items?
If the second option then it's already done.
Results could be seen here #555 (comment) for twice the size, 64 times the size and 1024 times the size of single circular buffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good call, sorry I missed that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem.
Btw in the last few days I tried to play with circular buffer size, tried to preallocate and reuse ring buffers with a pool and so on but nothing really brings benefits, only performance degradations.
It feels like FixedQueue was created by a dark magician who put an "unbeatable" spell on it. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is pretty well optimized. Liked the tradeoff of memory for more performance 👌