Hi Stuart,

thanks for raising this question!

I think caution is warranted here—a >1000% larger constant footprint for a <40% latency improvement is a difficult trade-off to make.

>However, our expectation is that LinkedBlockingQueue instances would be few in number.

This might be a fair assumption to make, but let's say that you use VirtualThreads and you are using a construct implemented on top of LinkedBlockingQueue to communicate between them (think some form of CSP-style thing) then you might be in the unfortunate situation of adding a lot of heap pressure.

Taking a step back, this is a classic space-time tradeoff situation, and I'm not (at this point) convinced that it is one we can make whole-sale for users without risking previously working applications to suddenly start throwing OutOfMemoryErrors.


On 2026-12-04 10: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.

Many thanks,
    Stuart
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

--
Cheers,
√


Viktor Klang
Software Architect, Java Platform Group
Oracle

Reply via email to