On 04/12/2026 09:34, Stuart Monteith wrote:
Hello core-libs-dev,
I've found under some circumstances that the
java.util.concurrent.LinkedBlockingQueue class can suffer from false
sharing on the "head" and "last" fields. By using the @Contended
annotation on those fields, this can be reduced when
the rate of queuing is high.
When doing so, the improvement that we see with the
o.o.b.j.util.concurrent.ProducerConsumer microbenchmark is on the
order of 40% to 13%. On one platform the result is reduced from
360ns/op down to 206ns/op, and at worst another platform
sees a result of 238ns/op reduced to 207ns/op.
However, there is a size penalty, running with compressed references
the change in size of LinkedBlockignQueue objects
is from 40 to 424 bytes and for uncompressed 64-bit references the
change is from 72 to 456 bytes. However, our
expectation is that LinkedBlockingQueue instances would be few in number.
The circumstances where this is likely to occur is when a
LinkedBlockingQueue is highly contended, with the producer and
consumer rapidly queuing and dequeuing small pieces of work.
In my research I've not noticed any discussion of @Contended in this
particular circumstance. I'd like to know if it has
been discussed elsewhere, and under what circumstances would such a
change be accepted? While an improvement on
contended fields can be easily demonstrated, the overall effect on
heap size and cache pollution is more difficult to
demonstrate.
Does the use-case require a bounded capacity? I'm wondering if you have
tried LinkedTransferQueue.
-Alan