-
Notifications
You must be signed in to change notification settings - Fork 567
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
SpscGrowableArrayQueue on failed check for look ahead the next element availability check is reversed leading to incorrect estimation of capacity #45
Comments
I'd say L91 check is valid, if intial == max than this is not growable and you should not use this queue. |
Okay. In that case, I'll use the modified version in RxJava where the queue must hold the number of elements its capacity provides. |
I was under the impression we're moving towards RxJava depending on JCTools? |
@akarnokd Also, did you re-benchmark for your use case using new implementation? |
First of all, the JCTools implementation failed/hung RxJava tests and the I haven't rerun the |
I'm not sure what you mean by the 'full capacity' issue. The queue interface doesn't have a notion of capacity, and all the queues already take some liberty with the requested capacity when they allocate to the nearest power of 2. Spsc in its current version utilizes the array up to the last element and grow able doesn't but since it's not specified as a requirement anywhere that they should I'm not sure there's a bug here. Perhaps more of an expected behaviour issue? |
Sure, it is an expected behavior issue and since my use case is different, I did the necessary adjustments locally and closed this issue. Still, L138 feels a bit odd. Apart from this under-utilization property, let's assume the buffer is at its full size and the lookahead step is 25% of it. Now if the queue gets 75% full, the look-ahead will find a non-null element ahead and falls through to L138 where the check says if the element after the insertion point (index) is occupied, insert the element at the index. However, since the queue is 25% empty, this check will be false and thus the offer rejects the insertion until the queue is drained below 75%. I'm not certain if L138 would ever pass unless the buffer size is really small (8?). |
Ok, i was confused about your initial comment, the check:
|
Fixed |
I found two more bugs:
L91: should allow initial size to be equal to max size and thus not growing.
L138-145: there is a missing case when the queue is at max capacity and there is exactly one space left: L138 checks if the index + 1 is occupied thus in the max capacity case, one can't have 128 elements in the queue but only 127; in the below max case, it won't use cell at index unless index + 1 is occupied, which is odd. I think the correct check would be:
Note the == check.
The text was updated successfully, but these errors were encountered: